Skip to content
New issue

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

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

Already on GitHub? # to your account

AttributeError: module 'enum' has no attribute '_decompose' when accessing frames property #47

Open
oliknight1 opened this issue Feb 1, 2023 · 1 comment · May be fixed by #49
Open

Comments

@oliknight1
Copy link

I'm trying to access the frames property to find the winner of a game and I get this error:

Traceback (most recent call last):
  File "/Users/oli/Documents/slippi-dashboard-api/test.py", line 5, in <module>
    print(game.frames[0])
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 69, in __repr__
    s = self._attr_repr(attr)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 62, in _attr_repr
    return attr + '=' + _format(getattr(self, attr))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 26, in _format
    return _format_collection(obj, '(', ')')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 15, in _format_collection
    elements = [_format(x) for x in coll]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 15, in <listcomp>
    elements = [_format(x) for x in coll]
                ^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 32, in _format
    return str(obj)
           ^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 69, in __repr__
    s = self._attr_repr(attr)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 62, in _attr_repr
    return attr + '=' + _format(getattr(self, attr))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 32, in _format
    return str(obj)
           ^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 69, in __repr__
    s = self._attr_repr(attr)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 62, in _attr_repr
    return attr + '=' + _format(getattr(self, attr))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 32, in _format
    return str(obj)
           ^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 69, in __repr__
    s = self._attr_repr(attr)
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 62, in _attr_repr
    return attr + '=' + _format(getattr(self, attr))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 30, in _format
    return repr(obj)
           ^^^^^^^^^
  File "/Users/oli/Library/Caches/pypoetry/virtualenvs/slippi-dashboard-api-Jhn0YU0Z-py3.11/lib/python3.11/site-packages/slippi/util
.py", line 93, in __repr__
    members, _ = enum._decompose(self.__class__, self._value_)

Code used to get the error:

from slippi import Game

game = Game("./replays/test2.slp")

print(game.frames[0])

Python version: 3.11.1

@Kered13
Copy link

Kered13 commented Mar 17, 2023

I just encountered this after upgrading Python myself. Based on the name, _decompose is a private function of the enum library, and should never have been used by py-slippi in the first place. I assume it was removed in some recent Python version, and now py-slippi is not working.

Here is a corrected version of the IntFlag.__repr__ function using only documented attributes of the enum library:

def __repr__(self):
    members = (name for name, value in self.__class__.__members__.items() if self & value)
    return '%s:%s' % (bin(self._value_), '|'.join(members))

Until this is, hopefully soon, fixed in the library, you can monkey patch the fix into your code with:

slippi.util.IntFlag.__repr__ = fixed_repr

@Kered13 Kered13 linked a pull request Mar 17, 2023 that will close this issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants