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

[BUG] Unable to pickle cpdef enum values from pure python because of attribute lookup error #5120

Closed
tarasko opened this issue Nov 8, 2022 · 2 comments · Fixed by #5124
Closed
Labels

Comments

@tarasko
Copy link

tarasko commented Nov 8, 2022

Describe the bug

pickle.dumps throws an exception when attempted to serialize enum value

>>> pickle.dumps(ValEnum.val1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <enum 'ValEnum'>: attribute lookup ValEnum on importlib._bootstrap failed

Code to reproduce the behaviour:

cpdef enum ValEnum:
    val1 = 1
    val2 = 2
import pickle
pickle.dumps(ValEnum.val1)

Expected behaviour

pickle.dumps should return serialized value instead of throwing an exception

Environment

OS: Linux 5.4.0-124-generic #140-Ubuntu SMP Thu Aug 4 02:23:37 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Python version [e.g. 3.10.6]
Cython version [e.g. 3.0.0a11]

Additional context

No response

@tarasko
Copy link
Author

tarasko commented Nov 8, 2022

I wonder if there is any easy workaround for this?

@da-woods da-woods added the defect label Nov 8, 2022
@da-woods
Copy link
Contributor

da-woods commented Nov 8, 2022

Thanks for the report. I suspect we just need to pass module and/or qualname arguments when we construct the enum.

The workaround probably involves casting it to int and pickling the int I suggest.

da-woods added a commit to da-woods/cython that referenced this issue Nov 10, 2022
(on Python >= 3.4).

Fixes cython#5120
scoder pushed a commit that referenced this issue Jan 10, 2023
(on Python >= 3.4).

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

Successfully merging a pull request may close this issue.

2 participants