MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _missing_

Method _missing_

tools/python-3.11.9-amd64/Lib/enum.py:1378–1468  ·  view source on GitHub ↗

Create a composite member containing all canonical members present in `value`. If non-member values are present, result depends on `_boundary_` setting.

(cls, value)

Source from the content-addressed store, hash-verified

1376
1377 @classmethod
1378 def _missing_(cls, value):
1379 """
1380 Create a composite member containing all canonical members present in `value`.
1381
1382 If non-member values are present, result depends on `_boundary_` setting.
1383 """
1384 if not isinstance(value, int):
1385 raise ValueError(
1386 "%r is not a valid %s" % (value, cls.__qualname__)
1387 )
1388 # check boundaries
1389 # - value must be in range (e.g. -16 <-> +15, i.e. ~15 <-> 15)
1390 # - value must not include any skipped flags (e.g. if bit 2 is not
1391 # defined, then 0d10 is invalid)
1392 flag_mask = cls._flag_mask_
1393 singles_mask = cls._singles_mask_
1394 all_bits = cls._all_bits_
1395 neg_value = None
1396 if (
1397 not ~all_bits <= value <= all_bits
1398 or value & (all_bits ^ flag_mask)
1399 ):
1400 if cls._boundary_ is STRICT:
1401 max_bits = max(value.bit_length(), flag_mask.bit_length())
1402 raise ValueError(
1403 "%r invalid value %r\n given %s\n allowed %s" % (
1404 cls, value, bin(value, max_bits), bin(flag_mask, max_bits),
1405 ))
1406 elif cls._boundary_ is CONFORM:
1407 value = value & flag_mask
1408 elif cls._boundary_ is EJECT:
1409 return value
1410 elif cls._boundary_ is KEEP:
1411 if value < 0:
1412 value = (
1413 max(all_bits+1, 2**(value.bit_length()))
1414 + value
1415 )
1416 else:
1417 raise ValueError(
1418 '%r unknown flag boundary %r' % (cls, cls._boundary_, )
1419 )
1420 if value < 0:
1421 neg_value = value
1422 value = all_bits + 1 + value
1423 # get members and unknown
1424 unknown = value & ~flag_mask
1425 aliases = value & ~singles_mask
1426 member_value = value & singles_mask
1427 if unknown and cls._boundary_ is not KEEP:
1428 raise ValueError(
1429 '%s(%r) --> unknown values %r [%s]'
1430 % (cls.__name__, value, unknown, bin(unknown))
1431 )
1432 # normal Flag?
1433 if cls._member_type_ is object:
1434 # construct a singleton enum pseudo-member
1435 pseudo_member = object.__new__(cls)

Callers

nothing calls this directly

Calls 7

maxFunction · 0.85
binFunction · 0.70
__new__Method · 0.45
appendMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected