apocalyptech / animalwellsave

Python-Based CLI Animal Well Savegame Editor
GNU General Public License v3.0
4 stars 1 forks source link

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

Closed bellezzza closed 5 months ago

bellezzza commented 5 months ago

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 commented 5 months ago

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: https://github.com/python/cpython/issues/88123

apocalyptech commented 5 months ago

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 commented 5 months ago

@apocalyptech thanks!