MCPcopy Index your code
hub / github.com/RustPython/RustPython / _missing_

Method _missing_

Lib/enum.py:1447–1537  ·  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

1445
1446 @classmethod
1447 def _missing_(cls, value):
1448 """
1449 Create a composite member containing all canonical members present in `value`.
1450
1451 If non-member values are present, result depends on `_boundary_` setting.
1452 """
1453 if not isinstance(value, int):
1454 raise ValueError(
1455 "%r is not a valid %s" % (value, cls.__qualname__)
1456 )
1457 # check boundaries
1458 # - value must be in range (e.g. -16 <-> +15, i.e. ~15 <-> 15)
1459 # - value must not include any skipped flags (e.g. if bit 2 is not
1460 # defined, then 0d10 is invalid)
1461 flag_mask = cls._flag_mask_
1462 singles_mask = cls._singles_mask_
1463 all_bits = cls._all_bits_
1464 neg_value = None
1465 if (
1466 not ~all_bits <= value <= all_bits
1467 or value & (all_bits ^ flag_mask)
1468 ):
1469 if cls._boundary_ is STRICT:
1470 max_bits = max(value.bit_length(), flag_mask.bit_length())
1471 raise ValueError(
1472 "%r invalid value %r\n given %s\n allowed %s" % (
1473 cls, value, bin(value, max_bits), bin(flag_mask, max_bits),
1474 ))
1475 elif cls._boundary_ is CONFORM:
1476 value = value & flag_mask
1477 elif cls._boundary_ is EJECT:
1478 return value
1479 elif cls._boundary_ is KEEP:
1480 if value < 0:
1481 value = (
1482 max(all_bits+1, 2**(value.bit_length()))
1483 + value
1484 )
1485 else:
1486 raise ValueError(
1487 '%r unknown flag boundary %r' % (cls, cls._boundary_, )
1488 )
1489 if value < 0:
1490 neg_value = value
1491 value = all_bits + 1 + value
1492 # get members and unknown
1493 unknown = value & ~flag_mask
1494 aliases = value & ~singles_mask
1495 member_value = value & singles_mask
1496 if unknown and cls._boundary_ is not KEEP:
1497 raise ValueError(
1498 '%s(%r) --> unknown values %r [%s]'
1499 % (cls.__name__, value, unknown, bin(unknown))
1500 )
1501 # normal Flag?
1502 if cls._member_type_ is object:
1503 # construct a singleton enum pseudo-member
1504 pseudo_member = object.__new__(cls)

Callers

nothing calls this directly

Calls 10

isinstanceFunction · 0.85
maxFunction · 0.85
hasattrFunction · 0.85
binFunction · 0.70
bit_lengthMethod · 0.45
__new__Method · 0.45
appendMethod · 0.45
itemsMethod · 0.45
joinMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected