Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
gh-137969: Fix double evaluation ofForwardRefs which rely on globals#140974
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
JelleZijlstra left a comment
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! Could you also add a unit test asserting that if a locals dictionary is passed in, it's not modified?
Uh oh!
There was an error while loading.Please reload this page.
Lib/annotationlib.py Outdated
| try: | ||
| globals[cell_name]=cell_value.cell_contents | ||
| ifcell_namenotinlocals: | ||
| locals[cell_name]=cell_value.cell_contents |
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.
Can you narrow the try-except so it only covers this line? (The part that can raise ValueError is the.cell_contents attribute read.)
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.
Hopefully replacing withsetdefault is fine - if the object doesn't have a 'setdefault' attribute, it will raise anAttributeError notValueError.
Uh oh!
There was an error while loading.Please reload this page.
dr-carlos commentedNov 6, 2025
Added one to test globals and locals, since they're both dicts which are mutable. |
Uh oh!
There was an error while loading.Please reload this page.
ref.evaluate(format=Format.FORWARDREF)objects #138075, but just adds new locals (without overwriting the actual locals), instead of using a new dictionary.__cell__nonlocal variables added to globals ingh-138151: Fix annotationlib handling of multiple nonlocals #138164globaldeclaration and resets across test runs (this broke buildbots last time).ref.evaluate(format=Format.FORWARDREF)returns a ForwardRef with a copied__globals__that no longer updates #137969