mirror of
https://github.com/python/cpython.git
synced 2025-08-23 18:24:46 +00:00
gh-99248: [Enum] fix negative number infinite loop (GH-99256)
[Enum] fix negative number infinite loop - _iter_bits_lsb() now raises a ValueError if a negative number is passed in - verify() now skips checking negative numbers for named flags
This commit is contained in:
parent
52f91c642b
commit
0b4ffb08cc
3 changed files with 23 additions and 2 deletions
|
@ -114,9 +114,12 @@ def _make_class_unpicklable(obj):
|
|||
setattr(obj, '__module__', '<unknown>')
|
||||
|
||||
def _iter_bits_lsb(num):
|
||||
# num must be an integer
|
||||
# num must be a positive integer
|
||||
original = num
|
||||
if isinstance(num, Enum):
|
||||
num = num.value
|
||||
if num < 0:
|
||||
raise ValueError('%r is not a positive integer' % original)
|
||||
while num:
|
||||
b = num & (~num + 1)
|
||||
yield b
|
||||
|
@ -1839,6 +1842,9 @@ class verify:
|
|||
if name in member_names:
|
||||
# not an alias
|
||||
continue
|
||||
if alias.value < 0:
|
||||
# negative numbers are not checked
|
||||
continue
|
||||
values = list(_iter_bits_lsb(alias.value))
|
||||
missed = [v for v in values if v not in member_values]
|
||||
if missed:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue