-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
bpo-46301: cover uncomparable values in Enum._convert_
#30472
Conversation
@@ -4477,6 +4485,19 @@ def test_convert(self): | |||
and name not in dir(IntEnum)], | |||
[], msg='Names other than CONVERT_TEST_* found.') | |||
|
|||
def test_convert_uncomparable(self): | |||
uncomp = enum.Enum._convert_( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, _convert_
was not tested on plain Enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_convert_
was not intended to be called on plain Enum
-- it's purpose it to convert existing constants in a module to enums, and existing constants will already be str
or int
(or possibly something else, like complex
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the UNCOMPARABLE_*
values as suggested above, and also add a test using a complex
type.
@AlexWaygood can you please add "skip news" to this PR? I can't add labels myself 🙂 |
@@ -4440,6 +4440,14 @@ def test__all__(self): | |||
CONVERT_STRING_TEST_NAME_E = 5 | |||
CONVERT_STRING_TEST_NAME_F = 5 | |||
|
|||
# We also need values that cannot be compared: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All we need for this test is for UNCOMPARABLE_*
to be different types of values:
UNCOMPABLE_A
= 5
UNCOMPABLE_C
= (9, 4)
UNCOMPABLE_B
= 'hello'
@@ -4477,6 +4485,19 @@ def test_convert(self): | |||
and name not in dir(IntEnum)], | |||
[], msg='Names other than CONVERT_TEST_* found.') | |||
|
|||
def test_convert_uncomparable(self): | |||
uncomp = enum.Enum._convert_( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the UNCOMPARABLE_*
values as suggested above, and also add a test using a complex
type.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
Thanks! I've added one more case with I have made the requested changes; please review again |
Thanks for making the requested changes! @ethanfurman: please review the changes made to this pull request. |
Thank you! 👍 |
Seems that this PR has broken the refleak buildbots: https://buildbot.python.org/all/#/builders/320/builds/269/ According to our buildbot policy, if this is not fixed in 24h we will need to revert |
@pablogsal thanks for the info! I would love to help to get this fixed, but I am not familiar with how refleak works. And since this is a test-only PR I am bit surprised that this happened 🤔
From https://buildbot.python.org/all/#/builders/384/builds/255 🤔 |
I was able to reproduce this locally on macos with
|
|
I am not at my computer so I cannot test, but the problem that happens in these cases where only tests are added is that the new tests are either modifying the global state or adding some sort of cache. |
Ok, looks like I've found the problem: Line 833 in 1bee9a4
When I comment this line out - tests pass, with it - we have a refleak. |
Yeah, this is an example of "modifying the global state". Tests should be idempotent, and they should leave everything as it was before |
Yes, you are right! These tests do modify the global state. They add a new class to the current module.
But this line is from Either way, I will open a new PR with |
The line The clue was good, though -- the global constants that are converted into enums need to be reset to their original values, either before or after the test runs. |
@sobolevn add
to the top of
to the bottom. Make similar changes to |
Oh, sorry, I've missed your comment in the morning 🙂 |
https://bugs.python.org/issue46301