MCPcopy Index your code
hub / github.com/python/cpython / __call__

Method __call__

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

Source from the content-addressed store, hash-verified

1965 def __init__(self, *checks):
1966 self.checks = checks
1967 def __call__(self, enumeration):
1968 checks = self.checks
1969 cls_name = enumeration.__name__
1970 if Flag is not None and issubclass(enumeration, Flag):
1971 enum_type = 'flag'
1972 elif issubclass(enumeration, Enum):
1973 enum_type = 'enum'
1974 else:
1975 raise TypeError("the 'verify' decorator only works with Enum and Flag")
1976 for check in checks:
1977 if check is UNIQUE:
1978 # check for duplicate names
1979 duplicates = []
1980 for name, member in enumeration.__members__.items():
1981 if name != member.name:
1982 duplicates.append((name, member.name))
1983 if duplicates:
1984 alias_details = ', '.join(
1985 ["%s -> %s" % (alias, name) for (alias, name) in duplicates])
1986 raise ValueError('aliases found in %r: %s' %
1987 (enumeration, alias_details))
1988 elif check is CONTINUOUS:
1989 values = set(e.value for e in enumeration)
1990 if len(values) < 2:
1991 continue
1992 low, high = min(values), max(values)
1993 missing = []
1994 if enum_type == 'flag':
1995 # check for powers of two
1996 for i in range(_high_bit(low)+1, _high_bit(high)):
1997 if 2**i not in values:
1998 missing.append(2**i)
1999 elif enum_type == 'enum':
2000 # check for missing consecutive integers
2001 for i in range(low+1, high):
2002 if i not in values:
2003 missing.append(i)
2004 else:
2005 raise Exception('verify: unknown type %r' % enum_type)
2006 if missing:
2007 raise ValueError(('invalid %s %r: missing values %s' % (
2008 enum_type, cls_name, ', '.join((str(m) for m in missing)))
2009 )[:256])
2010 # limit max length to protect against DOS attacks
2011 elif check is NAMED_FLAGS:
2012 # examine each alias and check for unnamed flags
2013 member_names = enumeration._member_names_
2014 member_values = [m.value for m in enumeration]
2015 missing_names = []
2016 missing_value = 0
2017 for name, alias in enumeration._member_map_.items():
2018 if name in member_names:
2019 # not an alias
2020 continue
2021 if alias.value < 0:
2022 # negative numbers are not checked
2023 continue
2024 values = list(_iter_bits_lsb(alias.value))

Callers

nothing calls this directly

Calls 9

setFunction · 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
joinMethod · 0.45

Tested by

no test coverage detected