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

Method __call__

Lib/enum.py:1936–2014  ·  view source on GitHub ↗
(self, enumeration)

Source from the content-addressed store, hash-verified

1934 def __init__(self, *checks):
1935 self.checks = checks
1936 def __call__(self, enumeration):
1937 checks = self.checks
1938 cls_name = enumeration.__name__
1939 if Flag is not None and issubclass(enumeration, Flag):
1940 enum_type = 'flag'
1941 elif issubclass(enumeration, Enum):
1942 enum_type = 'enum'
1943 else:
1944 raise TypeError("the 'verify' decorator only works with Enum and Flag")
1945 for check in checks:
1946 if check is UNIQUE:
1947 # check for duplicate names
1948 duplicates = []
1949 for name, member in enumeration.__members__.items():
1950 if name != member.name:
1951 duplicates.append((name, member.name))
1952 if duplicates:
1953 alias_details = ', '.join(
1954 ["%s -> %s" % (alias, name) for (alias, name) in duplicates])
1955 raise ValueError('aliases found in %r: %s' %
1956 (enumeration, alias_details))
1957 elif check is CONTINUOUS:
1958 values = set(e.value for e in enumeration)
1959 if len(values) < 2:
1960 continue
1961 low, high = min(values), max(values)
1962 missing = []
1963 if enum_type == 'flag':
1964 # check for powers of two
1965 for i in range(_high_bit(low)+1, _high_bit(high)):
1966 if 2**i not in values:
1967 missing.append(2**i)
1968 elif enum_type == 'enum':
1969 # check for missing consecutive integers
1970 for i in range(low+1, high):
1971 if i not in values:
1972 missing.append(i)
1973 else:
1974 raise Exception('verify: unknown type %r' % enum_type)
1975 if missing:
1976 raise ValueError(('invalid %s %r: missing values %s' % (
1977 enum_type, cls_name, ', '.join((str(m) for m in missing)))
1978 )[:256])
1979 # limit max length to protect against DOS attacks
1980 elif check is NAMED_FLAGS:
1981 # examine each alias and check for unnamed flags
1982 member_names = enumeration._member_names_
1983 member_values = [m.value for m in enumeration]
1984 missing_names = []
1985 missing_value = 0
1986 for name, alias in enumeration._member_map_.items():
1987 if name in member_names:
1988 # not an alias
1989 continue
1990 if alias.value < 0:
1991 # negative numbers are not checked
1992 continue
1993 values = list(_iter_bits_lsb(alias.value))

Callers

nothing calls this directly

Calls 13

issubclassFunction · 0.85
setFunction · 0.85
lenFunction · 0.85
minFunction · 0.85
maxFunction · 0.85
_high_bitFunction · 0.85
strFunction · 0.85
listClass · 0.85
_iter_bits_lsbFunction · 0.85
_is_single_bitFunction · 0.85
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected