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

Add backport of evaluate_forward_ref #497

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

Daraan
Copy link
Contributor

@Daraan Daraan commented Oct 30, 2024

Backports evaluate_forward_ref from JelleZijlstra's PR python/cpython#119891 / PEP 749.

The most tricky part seems to be in recursive ForwardRefs, at least in my tests they worked better in 3.9 and but not in 3.8 and 3.10. If someone has some nice examples how to break it I gladly add them.
Limitation has been added to the docs.

Tests are also tested against cpython main python/cpython@079875e39

@AlexWaygood AlexWaygood changed the title Add backport of evalaute_forward_ref Add backport of evaluate_forward_ref Oct 30, 2024
Comment on lines 3826 to +3827
SOURCE = 3
STRING = 3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess, SOURCE will be removed soon?

Comment on lines +8369 to +8370
if _FORWARD_REF_HAS_CLASS
else Final # will not raise error in older versions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure if Final should throw errors in earlier versions that do not implement __forward_is_class__

Comment on lines +8140 to +8142
# Assure that these are not in globals
assert X.__name__ not in globals()
assert Y.__name__ not in globals()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These asserts are important for test design; should I use self.assertNotIn instead?

@Daraan Daraan marked this pull request as ready for review October 30, 2024 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add typing_extensions.evaluate_forward_ref
1 participant