-
-
Notifications
You must be signed in to change notification settings - Fork 32.9k
gh-138425: Correctly partially evaluate global generics with undefined params in ref.evaluate(format=Format.FORWARDREF)
#138430
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
base: main
Are you sure you want to change the base?
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.
looks good
Misc/NEWS.d/next/Library/2025-09-03-18-26-07.gh-issue-138425.cVE9Ho.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: sobolevn <[email protected]>
Misc/NEWS.d/next/Library/2025-09-03-18-26-07.gh-issue-138425.cVE9Ho.rst
Outdated
Show resolved
Hide resolved
…fined generic tests Removed global overriding builtin test as it seemingly wasn't compatible with `get_annotations()`.
Note that this PR also inherently fixes builtins overriding globals in this particular code path. I was previously unable to come up with a test for this without using the undocumented from annotationlib import Format, get_annotations
class C:
y: alias[memoryview, undef]
mv = __builtins__["memoryview"]
del __builtins__["memoryview"]
fwdref = get_annotations(C, format=Format.FORWARDREF)["y"]
__builtins__["memoryview"] = mv
generic = fwdref.evaluate(
format=Format.FORWARDREF,
globals={"memoryview": int},
locals={"alias": dict}
)
self.assertNotIsInstance(generic, ForwardRef)
self.assertIs(generic.__origin__, dict)
self.assertEqual(len(generic.__args__), 2)
self.assertIs(generic.__args__[0], int)
self.assertIsInstance(generic.__args__[1], ForwardRef) It feels very unlikely this would happen in real code, and I'm not sure if it's a good idea to test given that "Since this is an implementation detail, it may not be used by alternate implementations of Python." (https://docs.python.org/3/library/builtins.html), and given that |
Good point, I think it's fine to skip the test in that case. Technical issue: your two PRs #138430 and #138075 will conflict with each other, and I won't be able to backport them to 3.14 until after 3.14.0 final comes out. So I'm planning to leave them open for now and land them once 3.14.0 final is out so I can sort out the merge conflicts and merge the backports without having to disrupt the RC process. |
ref.evaluate(format=Format.FORWARDREF)
not evaluating global generics with undefined params #138425