Skip to content

Commit

Permalink
Don't rely on Python 3.12+ enum __contains__
Browse files Browse the repository at this point in the history
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
  • Loading branch information
apocalyptech committed May 31, 2024
1 parent 4214448 commit 3e9dbce
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions animalwellsave/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,13 @@ def _post_value_set(self):
variable if the numeric data is contained within `self.choices`.
"""
if self.choices is not None:
if self.value in self.choices:
# In Python 3.12 we could check `self.value in self.choices`, as I was doing
# originally, but it turns out that's something added in 3.12, and I'd like
# to be compatible back to 3.10. See: https://github.com/python/cpython/issues/88123
# (not that this method is bad, of course -- more Pythonic, even, probably!)
try:
self.choice = self.choices(self.value)
else:
except ValueError:
self.choice = None

@property
Expand Down

0 comments on commit 3e9dbce

Please sign in to comment.