-
-
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
gh-85795: Add support for super()
in NamedTuple
subclasses
#129352
base: main
Are you sure you want to change the base?
Conversation
This needs a backport to 3.12 and 3.13. |
Changed my mind, let's not backport it :)
|
CPython disallows class Foo:
__classcell__ = None but this implementation allows from typing import NamedTuple
class Foo(NamedTuple):
__classcell__ = None should I pop from the origin class namespace with a sentinel object fallback instead of Errors should never pass silently, unless explicitly silenced. |
Ideally I feel like this fix would not involve adding a new parameter to
It seems like an unlikely situation, but I suppose this would be strictly-speaking more correct! |
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.
Mostly LGTM, but I have a few thoughts.
I like @ZeroIntensity's idea of moving |
20bfaeb
to
074df4c
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.
Nice. This LGTM now.
oh, except some tests are failing |
Co-authored-by: Alex Waygood <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
0d6dcbb
to
ee93519
Compare
Hah! How ignorant of me. I added another frame by wrapping the function and didn't fixup the existing frame refs ( |
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, with one tiny suggestion.
Co-authored-by: Peter Bierma <[email protected]>
Thanks @AlexWaygood and @ZeroIntensity for working through this and finding a better approach! One last thought is whether I should test cpython/Lib/test/test_super.py Lines 262 to 273 in c931d75
I'm leaving this decision to @rhettinger since he self-assigned this. I personally believe a possible regression allowing nonsense overwrites of __classcell__ in typing.NamedTuple subclasses is not harmful by any means and niche enough that and I wouldn't care about that case.
@rhettinger Please review. :) |
Fixes gh-85795.
A private parameter
_classcell
was added tocollections.namedtuple()
and its wrappers intyping
in order to deliver it to the targetedtype.__new__
.It's the easiest approach here.
__classcell__
is popped from the original class namespace, as it would otherwise leak to the end class (metaclasses should clean up the__classcell__
attribute).It is expected not to be added to typeshed, as the parameter is intended for internal use only.
After this PR, please consider a follow-up issue gh-129343 and the PR associated with it.
📚 Documentation preview 📚: https://cpython-previews--129352.org.readthedocs.build/