Skip to content

Commit 430e11e

Browse files
committed
Correct for enum module changes in Python>=3.11
1 parent e735902 commit 430e11e

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/tslumd/common.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ def to_str(self) -> str:
6666
def __str__(self):
6767
return self.name
6868

69+
@classmethod
70+
def all(cls):
71+
"""Iterate over all members
72+
73+
.. versionadded:: 0.0.6
74+
"""
75+
yield from cls.__members__.values()
76+
6977
def __format__(self, format_spec):
7078
if format_spec == '':
7179
return str(self)
@@ -110,7 +118,9 @@ def is_iterable(self) -> bool:
110118
"""
111119
if self == TallyType.all_tally:
112120
return True
113-
return self.name is None
121+
mask = 1 << (self.bit_length() - 1)
122+
return self ^ mask != 0
123+
114124

115125
@classmethod
116126
def all(cls) -> Iterator[TallyType]:
@@ -133,7 +143,7 @@ def from_str(s: str) -> TallyType:
133143
>>> TallyType.from_str('rh_tally')
134144
<TallyType.rh_tally: 1>
135145
>>> TallyType.from_str('rh|txt_tally')
136-
<TallyType.txt_tally|rh_tally: 3>
146+
<TallyType.rh_tally|txt_tally: 3>
137147
>>> TallyType.from_str('rh|txt|lh')
138148
<TallyType.all_tally: 7>
139149
>>> TallyType.from_str('all')
@@ -175,6 +185,16 @@ def __iter__(self) -> Iterator[TallyType]:
175185
if ttype in self:
176186
yield ttype
177187

188+
def __repr__(self):
189+
if not self.is_iterable:
190+
return super().__repr__()
191+
if self.name is not None:
192+
members = self.name
193+
else:
194+
members = '|'.join([m.name for m in self])
195+
return f'<{self.__class__.__name__}.{members}: {self.value}>'
196+
197+
178198
class TallyState(enum.IntFlag):
179199
OFF = 0 #: Off
180200
PREVIEW = 1 #: Preview

tests/test_sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async def wait_for_receiver():
281281
receiver.bind_async(loop, on_tally_updated=evt_listener.callback)
282282

283283
# Send a broadcast tally for each color setting all TallyType's to it
284-
for color in TallyColor:
284+
for color in TallyColor.all():
285285
color_kw = {k:color for k in color_kw.keys()}
286286
await sender.send_broadcast_tally(screen_index, **color_kw)
287287
await wait_for_receiver()

0 commit comments

Comments
 (0)