Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-138425: Correctly partially evaluate global generics with undefined params inref.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JelleZijlstra merged 8 commits intopython:mainfromdr-carlos:annolib-globals
Nov 2, 2025

Conversation

@dr-carlos
Copy link
Contributor

@dr-carlosdr-carlos commentedSep 3, 2025
edited by bedevere-appbot
Loading

Copy link

@auvipyauvipy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

looks good

dr-carlos reacted with thumbs up emoji
Co-authored-by: sobolevn <mail@sobolevn.me>
@python-cla-bot
Copy link

python-cla-botbot commentedSep 3, 2025
edited
Loading

All commit authors signed the Contributor License Agreement.

CLA signed

…fined generic testsRemoved global overriding builtin test as it seemingly wasn't compatible with `get_annotations()`.
@dr-carlos
Copy link
ContributorAuthor

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 undocumentedForwardRef() constructor. I have since done some thinking, and maybe I am missing something obvious, but all I could come up with was an (extremely contrived) test:

fromannotationlibimportFormat,get_annotationsclassC:y:alias[memoryview,undef]mv=__builtins__["memoryview"]del__builtins__["memoryview"]fwdref=get_annotations(C,format=Format.FORWARDREF)["y"]__builtins__["memoryview"]=mvgeneric=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__builtins__ seems to be either a module object or a dictionary depending on where you run the code.

@JelleZijlstra
Copy link
Member

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.

dr-carlos reacted with thumbs up emoji

@dr-carlos
Copy link
ContributorAuthor

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.

@JelleZijlstra Just a quick reminder of these PRs - any updates now that 3.14.0 final is out?

@JelleZijlstraJelleZijlstra merged commite66f87c intopython:mainNov 2, 2025
49 checks passed
@JelleZijlstraJelleZijlstra added the needs backport to 3.14bugs and security fixes labelNov 2, 2025
@miss-islington-app
Copy link

Thanks@dr-carlos for the PR, and@JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestNov 2, 2025
…defined params in `ref.evaluate(format=Format.FORWARDREF)` (pythonGH-138430)(cherry picked from commite66f87c)Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>Co-authored-by: sobolevn <mail@sobolevn.me>
@bedevere-app
Copy link

GH-140927 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelNov 2, 2025
JelleZijlstra pushed a commit that referenced this pull requestNov 2, 2025
…ndefined params in `ref.evaluate(format=Format.FORWARDREF)` (GH-138430) (#140927)gh-138425: Correctly partially evaluate global generics with undefined params in `ref.evaluate(format=Format.FORWARDREF)` (GH-138430)(cherry picked from commite66f87c)Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>Co-authored-by: sobolevn <mail@sobolevn.me>
@dr-carlos
Copy link
ContributorAuthor

Thanks for the merges@JelleZijlstra!

@dr-carlosdr-carlos deleted the annolib-globals branchNovember 3, 2025 01:23
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@sobolevnsobolevnsobolevn left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

+1 more reviewer

@auvipyauvipyauvipy approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@dr-carlos@JelleZijlstra@sobolevn@auvipy

[8]ページ先頭

©2009-2025 Movatter.jp