-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-85795: Raise a clear error when super()
is used in typing.NamedTuple
subclasses
#130082
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
gh-85795: Raise a clear error when super()
is used in typing.NamedTuple
subclasses
#130082
Conversation
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.
Reminder to change to TypeError
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 |
…amedTuple` subclasses
8def43c
to
ab6131d
Compare
(Force-pushed to update the author, I have a different e-mail now) |
…d in typed namedtuples
Let's cast the spell! ✨ I have made the requested changes; please review again. |
Thanks for making the requested changes! @JelleZijlstra: please review the changes made to this pull request. |
24956ef
to
e5539be
Compare
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.
LGTM as well, with one documentation nitpick.
….NamedTuple` subclasses (python#130082)
Follow-up to conclusions from gh-129352, closes gh-85795.
In #129352 (comment), @rhettinger and I agreed that a clear error message is needed when a user attempts to use
super()
intyping.NamedTuple
subclasses.I believe this PR should be backported.Since we no longer raise aRuntimeError
, this cannot be backported.About the PR
Pure presence of
__classcell__
is enough to confirm that__class__
closure was created to enablesuper()
calls.Tests for cases where
__classcell__
are manually set in typed named tuples were intentionally not added, as I don't see the value in considering these behaviors.Interestingly, I used a note admonition instead ofNo longer true, we raise.. versionchanged:: next
in the docs and it's completely backward-compatible: it applies to all relevant previous versions of Python. I considered making an "important" block instead, but I thinksuper()
is not often enough to support that idea.TypeError
instead ofRuntimeError
CC previous reviewers: @ZeroIntensity @AlexWaygood @JelleZijlstra @rhettinger
📚 Documentation preview 📚: https://cpython-previews--130082.org.readthedocs.build/