proto: skip the bitmask check if on old python versions

int.bit_count() requires Python 3.10, so let's skip it where not
available.
This commit is contained in:
Peter Hutterer 2023-03-17 10:53:02 +10:00
parent a95c9e1799
commit bba921329d

View file

@ -277,8 +277,11 @@ class Enum:
if self.is_bitfield:
if e.value < 0:
raise ValueError("Bitmasks must not be less than zero")
if e.value.bit_count() > 1:
raise ValueError("Bitmasks must have exactly one bit set")
try:
if e.value.bit_count() > 1:
raise ValueError("Bitmasks must have exactly one bit set")
except AttributeError:
pass # bit_count() requires Python 3.10
self.entries.append(entry)