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

When x is an Enum, duper get_reduce raises an error #1

Open
mikelane opened this issue May 30, 2023 · 2 comments
Open

When x is an Enum, duper get_reduce raises an error #1

mikelane opened this issue May 30, 2023 · 2 comments

Comments

@mikelane
Copy link

The problem is here. Since an Enum doesn't have an instance of self, when __reduce_ex__(4) is called, you will get an error telling you that you are missing one required positional argument. In order to call __reduce_ex__(4) on an Enum, you'd have to use one of the concrete enum values. For example:

>>> from enum import Enum
>>> class Test(Enum):
  2     FOO = 1
>>> Test.__reduce_ex__(4)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: __reduce_ex__() missing 1 required positional argument: 'proto'

__reduce_ex__() missing 1 required positional argument: 'proto'
>>> Test.FOO.__reduce_ex__(4)
(<enum 'Test'>, (1,))
>>>

I'm still digging into the code to fully understand what's going on here, so I'm don't have enough context to give a good recommendation. It is perhaps the case that you'd have to iterate over each of the enum values to call __reduce_ex__(4) on them one-by-one. Or perhaps it is the case that Enums are not able to be used by this method.

@Bobronium
Copy link
Owner

Hi, thanks for report and in-depth description!

Sorry for a long answer, took a pause from GitHub :)

I see the issue you're describing, but can't come up with a use case that would reproduce it.

Please, provide end-to-end example of how you're using duper and the stack trace you're getting.

PR is also welcomed, once issue is confirmed!

@th3w1zard1
Copy link

Took a quick look at this issue, this one may be a bit challenging especially due to the enum changes over the last few Python minor versions. Enum class does a couple of gnarly things under the hood to get it working.

In most scenarios, I can't imagine why you'd need a duplicate Enum class? Isn't the whole point to represent static data?

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

3 participants