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 39 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?

Copy link
Member

Choose a reason for hiding this comment

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

We should just remove SOURCE since we never released this enum.

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 wonder if the name change & doc changes should possible addressed by another PR

src/test_typing_extensions.py Outdated Show resolved Hide resolved
src/test_typing_extensions.py Outdated Show resolved Hide resolved
@Daraan Daraan marked this pull request as ready for review October 30, 2024 18:51
Comment on lines 3826 to 3827
SOURCE = 3
STRING = 3
Copy link
Member

Choose a reason for hiding this comment

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

We should just remove SOURCE since we never released this enum.

src/typing_extensions.py Show resolved Hide resolved
src/typing_extensions.py Outdated Show resolved Hide resolved
src/test_typing_extensions.py Outdated Show resolved Hide resolved
src/test_typing_extensions.py Outdated Show resolved Hide resolved
src/test_typing_extensions.py Outdated Show resolved Hide resolved
localns,
type_params,
owner,
) in unroll_cases(cases, locals()):
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure all this indirection makes the test cases better. It becomes harder to verify the tests behave as expected with so much logic between the definition of the tests and the actual tests.

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 share that sentiment. I did some reordering to bring the actual test and case definition closer together, but it does not reduce the overall code in that function.

So far I do not see a good way how to simplify it in a nice way. If you/anyone has suggestions on how to restructure / parts to remove I am open for it.

Copy link
Member

Choose a reason for hiding this comment

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

I'd simply write explicit test cases for some important cases, instead of attempting to create an abstraction around them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, Yes I think that looks better now. Thank you.

@Daraan Daraan marked this pull request as draft December 14, 2024 13:05
@Daraan Daraan marked this pull request as ready for review December 14, 2024 15:01
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
2 participants