8000 gh-85795: Raise a clear error when `super()` is used in `typing.NamedTuple` subclasses by bswck · Pull Request #130082 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

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

Merged
merged 3 commits into from
Mar 6, 2025

Conversation

bswck
Copy link
Contributor
@bswck bswck commented Feb 13, 2025

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() in typing.NamedTuple subclasses.

I believe this PR should be backported. Since we no longer raise a RuntimeError, this cannot be backported.

About the PR

Pure presence of __classcell__ is enough to confirm that __class__ closure was created to enable super() 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 of .. 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 think super() is not often enough to support that idea. No longer true, we raise TypeError instead of RuntimeError

CC previous reviewers: @ZeroIntensity @AlexWaygood @JelleZijlstra @rhettinger


📚 Documentation preview 📚: https://cpython-previews--130082.org.readthedocs.build/

Copy link
Member
@JelleZijlstra JelleZijlstra left a 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

@bedevere-app
Copy link
bedevere-app bot commented Mar 3, 2025

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.

@bswck bswck force-pushed the eligible-classcell-error-message branch from 8def43c to ab6131d Compare March 4, 2025 07:01
@ghost
Copy link
ghost commented Mar 4, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bswck
Copy link
Contributor Author
bswck commented Mar 4, 2025

(Force-pushed to update the author, I have a different e-mail now)

@bswck
Copy link
Contributor Author
bswck commented Mar 4, 2025

Let's cast the spell! ✨

I have made the requested changes; please review again.

@bedevere-app
Copy link
bedevere-app bot commented Mar 4, 2025

Thanks for making the requested changes!

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

@bedevere-app bedevere-app bot requested a review from JelleZijlstra March 4, 2025 07:10
@bswck bswck force-pushed the eligible-classcell-error-message branch from 24956ef to e5539be Compare March 4, 2025 07:14
Copy link
Member
@ZeroIntensity ZeroIntensity left a 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.

@JelleZijlstra JelleZijlstra merged commit 293fa34 into python:main Mar 6, 2025
43 of 46 checks passed
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
@bswck bswck deleted the eligible-classcell-error-message branch April 28, 2025 20:38
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.

__class__ not set in typing.NamedTuple
3 participants
0