Skip to content

Commit 3e9dbce

Browse files
committed
Don't rely on Python 3.12+ enum __contains__
Turns out the old implementation here relied on a feature added in Python 3.12. Converting that to a version that will work on older Pythons, too. This fixes bug #1. See: python/cpython#88123
1 parent 4214448 commit 3e9dbce

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎animalwellsave/datafile.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,13 @@ def _post_value_set(self):
345345
variable if the numeric data is contained within `self.choices`.
346346
"""
347347
if self.choices is not None:
348-
if self.value in self.choices:
348+
# In Python 3.12 we could check `self.value in self.choices`, as I was doing
349+
# originally, but it turns out that's something added in 3.12, and I'd like
350+
# to be compatible back to 3.10. See: https://github.com/python/cpython/issues/88123
351+
# (not that this method is bad, of course -- more Pythonic, even, probably!)
352+
try:
349353
self.choice = self.choices(self.value)
350-
else:
354+
except ValueError:
351355
self.choice = None
352356

353357
@property

0 commit comments

Comments
 (0)