Skip to content

gh-141174: Test re-stringifying a ForwardRef - #155689

Merged
JelleZijlstra merged 1 commit into
python:mainfrom
dr-carlos:annolib-test-re-eval-extra-names
Aug 13, 2026
Merged

gh-141174: Test re-stringifying a ForwardRef#155689
JelleZijlstra merged 1 commit into
python:mainfrom
dr-carlos:annolib-test-re-eval-extra-names

Conversation

@dr-carlos

@dr-carlos dr-carlos commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Currently, every ForwardRef.evaluate(format=Format.STRING) test in test_annotationlib is done with an empty __resolved_string_cache__, so there is no test that re-evaluations are correct (or that they actually use the cache).

That is to say, the condition self.__resolved_str_cache__ is None is always true:

if self.__resolved_str_cache__ is None:

Thus, this PR adds a simple test to re-stringify a stringified fwdref.

That said, I'm not 100% on whether the current test is correct: it's testing the behaviour that the cache has to be returned identically - which is the correct behaviour, and this test already tests the content of the cache - but I'm not sure if we want to cement that exact behaviour. So, happy to make it an equality (instead of identity) check if it's preferred.

@bedevere-app bedevere-app Bot added the tests Tests in the Lib/test dir label Aug 13, 2026
@dr-carlos dr-carlos changed the title gh-141174: Test re-evaluation of a ForwardRef with STRING format gh-141174: Test re-stringifying a ForwardRef Aug 13, 2026
@JelleZijlstra JelleZijlstra added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 13, 2026
@JelleZijlstra
JelleZijlstra enabled auto-merge (squash) August 13, 2026 14:14
@JelleZijlstra
JelleZijlstra merged commit 5dab490 into python:main Aug 13, 2026
62 checks passed
@miss-islington-app

Copy link
Copy Markdown

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

@bedevere-app

bedevere-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

GH-155707 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 13, 2026
@bedevere-app

bedevere-app Bot commented Aug 13, 2026

Copy link
Copy Markdown

GH-155708 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Aug 13, 2026
JelleZijlstra pushed a commit that referenced this pull request Aug 13, 2026
…55708)

Test that re-evaluating a `ForwardRef` with `STRING` format uses the cache
(cherry picked from commit 5dab490)

Co-authored-by: dr-carlos <77367421+dr-carlos@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants