Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType' #1

Closed
bellezzza opened this issue May 30, 2024 · 3 comments
Closed
Assignees

Comments

@bellezzza
Copy link

Greetings. I am having trouble using your utility in linux:

$ ./aw.py -i ../AnimalWell.sav 
Traceback (most recent call last):
  File "/Animal Well/pyanimalwell/./aw.py", line 26, in <module>
    animalwell.cli.main()
  File "/Animal Well/pyanimalwell/animalwell/cli.py", line 855, in main
    with Savegame(args.filename) as save:
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Animal Well/pyanimalwell/animalwell/savegame.py", line 1469, in __init__
    self._read()
  File "/Animal Well/pyanimalwell/animalwell/savegame.py", line 1501, in _read
    Slot(self, 0, 0x00018),
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/Animal Well/pyanimalwell/animalwell/savegame.py", line 1307, in __init__
    self._parse()
  File "/Animal Well/pyanimalwell/animalwell/savegame.py", line 1397, in _parse
    self.selected_equipment = NumChoiceData(self, UInt8, Equipped, 0x1EA)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Animal Well/pyanimalwell/animalwell/datafile.py", line 318, in __init__
    super().__init__(parent, num_type, offset=offset)
  File "/Animal Well/pyanimalwell/animalwell/datafile.py", line 141, in __init__
    self._post_value_set()
  File "/Animal Well/pyanimalwell/animalwell/datafile.py", line 342, in _post_value_set
    if self.value in self.choices:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/enum.py", line 745, in __contains__
    raise TypeError(
TypeError: unsupported operand type(s) for 'in': 'int' and 'EnumType'

I'm playing Animal Well through Wine, the --help option works fine, but when using any options with savegame file - this error occurs. Could you please clarify what the problem is?

@apocalyptech
Copy link
Owner

apocalyptech commented May 31, 2024

Oh, hello! Thanks for the report, sorry I didn't notice it until today!

So, it turns out that that bit of code is relying on something that doesn't work until Python 3.12! That's unintentional; I'll figure out a way to work around it. My main desktop's been using 3.12 so I didn't even realize I was doing something that required such a newer version. The minimum-version target that I'd been hoping for is 3.10.

Anyway, in the meantime, if it's feasible to update to Python 3.12, that should fix you up, but I'll hope to have a fix in place within the hour, so hang tight.

(I too am running Linux and run Animal Well via Wine/Proton, btw, so we've got similar environments in that regard. Cheers!)

Sample code that triggers the same error (works in 3.12 but not 3.11):

import enum

class Foo(enum.Enum):
    ONE = 1
    TWO = 2
    THREE = 3
    
if 2 in Foo:
    print('yo!')

... and also for my own reference, the issue where this functionality was added: python/cpython#88123

apocalyptech added a commit that referenced this issue May 31, 2024
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
@apocalyptech apocalyptech self-assigned this May 31, 2024
@apocalyptech
Copy link
Owner

Okay, easy enough fix there. I believe this should work properly on Pythons as old as 3.10 now, so you should be good to go! I've only done limited testing on my 3.11 install, so let me know if anything else unexpected pops up. I'll close this out for now though. Thanks again!

@bellezzza
Copy link
Author

@apocalyptech thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants