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

python 3.9.2 seems to break enumfields #65

Closed
jadedarko opened this issue Mar 11, 2021 · 3 comments
Closed

python 3.9.2 seems to break enumfields #65

jadedarko opened this issue Mar 11, 2021 · 3 comments

Comments

@jadedarko
Copy link

After upgrading to python 3.9.2 I am now unable to import from the enumfields package

3.9.2 changed the way subclassing and multiple inheritance works so it might be related?

Python 3.9.2 (default, Feb 20 2021, 20:59:40) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from enumfields import EnumIntegerField
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/__init__.py", line 1, in <module>
    from .enums import Enum, IntEnum
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 28, in <module>
    class Enum(EnumMeta('Enum', (BaseEnum,), _EnumDict())):
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 18, in __new__
    obj = BaseEnumMeta.__new__(mcs, name, bases, attrs)
  File "/usr/lib/python3.9/enum.py", line 212, in __new__
    classdict['__doc__'] = 'An enumeration.'
  File "/usr/lib/python3.9/enum.py", line 97, in __setitem__
    if _is_private(self._cls_name, key):
AttributeError: '_EnumDict' object has no attribute '_cls_name'
>>> from enumfields import EnumField
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/__init__.py", line 1, in <module>
    from .enums import Enum, IntEnum
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 28, in <module>
    class Enum(EnumMeta('Enum', (BaseEnum,), _EnumDict())):
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 18, in __new__
    obj = BaseEnumMeta.__new__(mcs, name, bases, attrs)
  File "/usr/lib/python3.9/enum.py", line 212, in __new__
    classdict['__doc__'] = 'An enumeration.'
  File "/usr/lib/python3.9/enum.py", line 97, in __setitem__
    if _is_private(self._cls_name, key):
AttributeError: '_EnumDict' object has no attribute '_cls_name'
>>> import enumfields
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/__init__.py", line 1, in <module>
    from .enums import Enum, IntEnum
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 28, in <module>
    class Enum(EnumMeta('Enum', (BaseEnum,), _EnumDict())):
  File "/var/www/.venv/lib/python3.9/site-packages/enumfields/enums.py", line 18, in __new__
    obj = BaseEnumMeta.__new__(mcs, name, bases, attrs)
  File "/usr/lib/python3.9/enum.py", line 212, in __new__
    classdict['__doc__'] = 'An enumeration.'
  File "/usr/lib/python3.9/enum.py", line 97, in __setitem__
    if _is_private(self._cls_name, key):
AttributeError: '_EnumDict' object has no attribute '_cls_name'
@jadedarko
Copy link
Author

From what I can tell, EnumMeta.__prepare__ doesn't seem to be used to generate the attrs dict enumfields uses

A hack to bypass this is to set attrs._cls_name to cls before invoking __new__, but that's obviously not ideal?

@jadedarko
Copy link
Author

ah, that's exactly what django-enumfields does:

hzdg/django-enumfields@8a54ab6

Sorry for the noise, I'll swap to using that package.

@Swamii
Copy link
Contributor

Swamii commented Feb 27, 2023

Closing this since it doesn't seem related to our package

@Swamii Swamii closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2023
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