-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Using functools.partial to make functions not considered as methods when given as enum values no longer works #125316
Comments
Confirmed on current main as well, technically a 3.13 regression. |
This is an intentional change, and it is documented. See #121027. Using |
@serhiy-storchaka maybe my title was not well formulated. This is what my issue boiled down to in my mind but I realize this is not exactly my problem, my problem is with the behavior I laid out in the snippet. It used to be that we could use At least there is still the wrapper class approach that works! I guess I'll just update the stackoverflow thread I mentioned in case people run into that. |
I should probably add that using |
As was mentioned in other answer, there is a better solution -- use |
Thanks for the tip! I had seen that answer but since it wasn't upvoted much I didn't try 😅 |
A FutureWarning with suggestion to use enum.member() is now emitted when the partial instance is used as an enum member.
#125361 should fix this for 3.13. It restores the old behavior of We tried to emit a warning about future behavior change, but adding a warning already changed the behavior in some cases. |
This comment was marked as off-topic.
This comment was marked as off-topic.
No, this is clearly wrong. #121089 was an intentional break in backwards compatibility, disregarding PEP-387 with the argument that "this will only rarely break code". |
Yes, but this specific case with |
Bug report
Bug description:
On python 3.10-3.12, the following snippet prints
True
, while on Python 3.13.0 it printsFalse
:This is because
MyCallables.B
is considered to befunctools.partial(<function b at 0x756d7f0065c0>)
on 3.13.0, when it used to be<MyCallables.B: functools.partial(<function b at 0x71f7cbc407c0>)>
before.This is something I've been using to allow function values in enums not to be considered methods, which I most likely got from this thread. In the example above,
A
would always be considered a method.It seems like on 3.13.0, the "wrapper class" approach is the only one that works.
CPython versions tested on:
3.10, 3.11, 3.12, 3.13
Operating systems tested on:
Linux, Windows
Linked PRs
The text was updated successfully, but these errors were encountered: