-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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-128632: fix segfault on nested __classdict__ type param #128744
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
@@ -2607,6 +2607,14 @@ def test_continuation_bad_indentation(self): | |||
|
|||
self.assertRaises(IndentationError, exec, code) | |||
|
|||
@support.cpython_only | |||
def test_disallowed_type_param_names(self): | |||
# See gh-128632 |
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.
Could you also test the following related cases:
- Using a generic function or type alias instead of a class with these names for the type parameters
- Using the names
__classcell__
and__classdictcell__
, which appear internally in the implementation.
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.
Added func and alias tests. Didn't add __classcell__
or __classdictcell__
tests as those are not excluded and don't cause problems currently. Do you want to add them to the forbidden list?
>>> class A:
... class B[__classcell__]: print(type(__classcell__))
...
<class 'typing.TypeVar'>
>>> class A:
... class B[__classdictcell__]: print(type(__classdictcell__))
...
<class 'typing.TypeVar'>
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.
Thanks for adding the tests! I want the *cell*
names to also be tested, because they're also somewhat likely to cause problems, even if they don't currently crash.
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.
So I interpret 'somewhat likely to cause problems' to mean yes disallow these names (and test them).
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.
Since they work fine now we should not disallow them, especially because we'd want to backport this change. However, we should have a test to make sure future changes don't introduce crashes with these names.
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.
Names re-allowed and tests added. Also re-allowed __class__
as that doesn't crash either even though it is special.
Just a reminder, according to @ZeroIntensity this needs backporting to 3.13 and 3.12. |
I'm going to yield to Jelle. This seems complex enough that backporting could be too risky. |
Had a look and doesn't look too bad, same functions are present to fix. |
Misc/NEWS.d/next/Core_and_Builtins/2025-01-11-20-11-28.gh-issue-128632.ryhnKs.rst
Outdated
Show resolved
Hide resolved
…e-128632.ryhnKs.rst
Add reserved name check in
symtable.c:symtable_visit_type_param_bound_or_default()
for__class__
and__classdict__
to prevent segfault when__classdict__
is used.