Repository navigation
Reject stale GenericAlias parameters on Python 3.15 #9069
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
Changes from 1 commit
9c3351f
e92e032
c643a85
0dd2d8b
5ceff65
4809c5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Validate stale cached parameters and retain the Python regression without obsolete reference prerequisites. Assisted-by: OpenAI Codex:model identifier unavailable
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,3 +89,25 @@ def __module__(self): | |
| ) | ||
| assert alias_namespace["alias"].__module__ is None | ||
| assert alias_module_lookups == [] | ||
|
|
||
|
|
||
| # GenericAlias rejects parameters added after its parameter tuple was cached. | ||
| from types import GenericAlias | ||
|
|
||
|
|
||
| class LateParameter: | ||
| def __repr__(self): | ||
| return "late_parameter" | ||
|
|
||
|
|
||
| first = LateParameter() | ||
| first.__typing_subst__ = lambda value: value | ||
| late = LateParameter() | ||
| alias = GenericAlias(dict, (first, late)) | ||
| assert alias.__parameters__ == (first,) | ||
| late.__typing_subst__ = lambda value: value | ||
| with assert_raises(TypeError) as caught: | ||
| alias[0] | ||
| assert str(caught.exception) == ( | ||
| "argument late_parameter with __typing_subst__ was not found in __parameters__" | ||
|
Comment on lines
+109
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This new assertion block adds test logic to AGENTS.md reference: AGENTS.md:L273-L280 Useful? React with 👍 / 👎. |
||
| ) | ||
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.
When
__typing_subst__is added before an alias's first parameter lookup, this return treats the parameter as stale even though Python 3.15 has not cached__parameters__yet. For example, letlate.__parameters__ == (T,), createGenericAlias(list, late), setlate.__typing_subst__ = lambda x: x, and evaluatealias[int]; Python returnslist[int], butPyGenericAlias::neweagerly saved(T,), solatemissestuple_indexand this branch raises. Lazily materialize or track the parameter cache so the guard applies only after it was actually cached.AGENTS.md reference: AGENTS.md:L7-L7
Useful? React with 👍 / 👎.