Skip to content
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

ForwardRef: do not cache evaluated value #129464

Closed
JelleZijlstra opened this issue Jan 30, 2025 · 1 comment
Closed

ForwardRef: do not cache evaluated value #129464

JelleZijlstra opened this issue Jan 30, 2025 · 1 comment

Comments

@JelleZijlstra
Copy link
Member

Currently, when a ForwardRef is successfully evaluated, we store the resulting value and on subsequent calls return it immediately, regardless of the arguments passed to ForwardRef.evaluate().

This is currently implemented here:

if self.__forward_evaluated__:

It matches previous behavior in 3.13:

if not self.__forward_evaluated__ or localns is not globalns:

I think this is confusing: if you call evaluate() on a ForwardRef that was already evaluated, we ignore whatever globals/locals/type_params you pass in and return whatever the result of the previous evaluation was. It would make more sense to me for evaluate() to re-evaluate the ForwardRef every time it is called. Callers can add caching if they want to in a more intelligent way.

As for #129463, cc @agronholm @Viicos @leycec.

@JelleZijlstra
Copy link
Member Author

Duplicate of #128593.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant