Skip to content

[3.7] bpo-34282: Fix Enum._convert shadowing members named _convert #9034

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

Merged
merged 6 commits into from
Sep 10, 2018

Conversation

orlnub123
Copy link
Contributor

@orlnub123 orlnub123 commented Sep 2, 2018

This is the 3.7 patch for the issue below.

https://bugs.python.org/issue34282

Lib/enum.py Outdated
# issue34282: Members named _convert should take precedence over
# the _convert method except if the enum also has a behavior named
# _convert. In which case, it falls back to the default
# behavior > member ordering where the behavior takes precedence.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should never be a member and a method with the same name. Besides _convert (which is a bug) are there any other examples?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I was referring to:

>>> import enum
>>>
>>> class Base(enum.Enum):
...     def test(self): ...
...
>>> class Test(Base):
...     test = enum.auto()
...
>>> Test.test
<function Base.test at 0x000002090A5AD730>

It doesn't seem constricted to just _convert.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same bug, though. Fixing the shadowing bug will resolve this case as well. Enums are special in many ways, but subclass declarations should still override parent's.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that's out of scope for this PR. I think it would be better served to close this and create a separate PR (and issue?) for it against the master branch and backport that to 3.7 and 3.6. We should still keep the _convert rename for 3.8 though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach would be to add it to #8568 and rewrite the code here but I'm not sure if fixing multiple things in a single PR is good practice. The titles and news entries would also have to change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said in https://bugs.python.org/msg324415, we'll need a patch for 3.7- to fix the member not showing up, a patch in 3.8 to do a rename and deprecation warning, and a reminder to remove the deprecation and legacy _convert in 3.9.

So use one of these two PRs for one, and the other for the other. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter two are fine but if we're going to fix the member not showing up by fixing the shadowing bug shouldn't it also be added to #8568? It affects more than just _convert so having the above code snippet change for 3.7-3.6 and then revert in 3.8 would be strange.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the actual fix from the 3.7 patch needs to also be in the 3.8 patch.

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@orlnub123
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ethanfurman: please review the changes made to this pull request.

@ethanfurman
Copy link
Member

Looking good. Now we need one or two tests: one for verifying that DynamicClassAttributes are not shadowed (if not already there), and one to verify that non-DynamicClassAttributes are shadowed.

@orlnub123
Copy link
Contributor Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@ethanfurman: please review the changes made to this pull request.

@orlnub123
Copy link
Contributor Author

Sorry to bother you, but shouldn't this be backported to 3.6?

@miss-islington
Copy link
Contributor

Thanks @orlnub123 for the PR, and @ethanfurman for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Sep 12, 2018
…nvert (pythonGH-9034)

* Fix Enum._convert shadowing members named _convert
(cherry picked from commit c0d63bf)

Co-authored-by: orlnub123 <orlnub123@gmail.com>
@bedevere-bot
Copy link

GH-9229 is a backport of this pull request to the 3.6 branch.

@ethanfurman
Copy link
Member

Not a bother, and yes, thank you.

ethanfurman pushed a commit that referenced this pull request Oct 6, 2018
…nvert (GH-9034) (GH-9229)

* Fix Enum._convert shadowing members named _convert
Co-authored-by: orlnub123 <orlnub123@gmail.com>
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

Successfully merging this pull request may close these issues.

5 participants