bitmask.py: formatting fixes

This commit is contained in:
dogeystamp 2022-08-03 15:23:28 -04:00
parent d4d81c14ca
commit 81055b0487
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 9 additions and 14 deletions

View File

@ -50,7 +50,7 @@ class Bitmask:
self._value = 0 self._value = 0
# Placeholder, modified later in __mask_op() # Placeholder, modified later in __mask_op()
self._AllFlags = IntFlag('', '') self._AllFlags = IntFlag("", "")
for flag in flags: for flag in flags:
self.add(flag) self.add(flag)
@ -90,7 +90,7 @@ class Bitmask:
types.append(type_name(self.AllFlags)) types.append(type_name(self.AllFlags))
if len(types) > 1: if len(types) > 1:
return ', '.join(types[:-1]) + " or " + types[-1] return ", ".join(types[:-1]) + " or " + types[-1]
else: else:
return types[0] return types[0]
@ -113,13 +113,10 @@ class Bitmask:
return False return False
else: else:
return True return True
elif issubclass(type(item), self.AllFlags) \ elif issubclass(type(item), self.AllFlags) or not self.defined:
or not self.defined:
return bool(self.value & item) return bool(self.value & item)
else: else:
raise TypeError( raise TypeError(f"item must be {self.__format_types()}")
f"item must be {self.__format_types()}"
)
def __iter__(self): def __iter__(self):
"""Return list of enabled flags.""" """Return list of enabled flags."""

View File

@ -146,9 +146,9 @@ def test_and_operator():
assert Bitmask() & Desc.ROUND == Bitmask() assert Bitmask() & Desc.ROUND == Bitmask()
# AND of bitmasks # AND of bitmasks
assert Bitmask(Desc.FUNKY, Desc.SONAR) & Bitmask( assert Bitmask(Desc.FUNKY, Desc.SONAR) & Bitmask(Desc.FUNKY, Desc.ROUND) == Bitmask(
Desc.FUNKY, Desc.ROUND Desc.FUNKY
) == Bitmask(Desc.FUNKY) )
assert Bitmask(Desc.FUNKY, Desc.ROUND) & Bitmask(Desc.SMALL) == Bitmask() assert Bitmask(Desc.FUNKY, Desc.ROUND) & Bitmask(Desc.SMALL) == Bitmask()
assert Bitmask() & Bitmask() == Bitmask() assert Bitmask() & Bitmask() == Bitmask()
@ -207,8 +207,7 @@ def test_subtract():
Desc.SMALL, Desc.ROUND Desc.SMALL, Desc.ROUND
) == Bitmask(Desc.FUNKY) ) == Bitmask(Desc.FUNKY)
assert ( assert (
Bitmask(Desc.FUNKY, Desc.SMALL) - Bitmask(Desc.SMALL, Desc.FUNKY) Bitmask(Desc.FUNKY, Desc.SMALL) - Bitmask(Desc.SMALL, Desc.FUNKY) == Bitmask()
== Bitmask()
) )
@ -233,8 +232,7 @@ def test_xor_operator():
Desc.SMALL, Desc.FUNKY, Desc.ROUND Desc.SMALL, Desc.FUNKY, Desc.ROUND
) )
assert ( assert (
Bitmask(Desc.FUNKY, Desc.ROUND) ^ Bitmask(Desc.FUNKY, Desc.ROUND) Bitmask(Desc.FUNKY, Desc.ROUND) ^ Bitmask(Desc.FUNKY, Desc.ROUND) == Bitmask()
== Bitmask()
) )
assert Bitmask() ^ Bitmask() == Bitmask() assert Bitmask() ^ Bitmask() == Bitmask()