-
-
Notifications
You must be signed in to change notification settings - Fork 110
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Jelle Zijlstra <[email protected]>
evalaute_forward_ref
evaluate_forward_ref
restructuring & comments
Co-authored-by: Jelle Zijlstra <[email protected]>
src/typing_extensions.py
Outdated
SOURCE = 3 | ||
STRING = 3 |
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.
I guess, SOURCE
will be removed soon?
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.
We should just remove SOURCE since we never released this enum.
src/typing_extensions.py
Outdated
SOURCE = 3 | ||
STRING = 3 |
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.
We should just remove SOURCE since we never released this enum.
src/typing_extensions.py
Outdated
value, exec, msg, is_argument=True, *, module=None, allow_special_forms=False | ||
): | ||
""" | ||
A forgiving version of typing._type_check to be executed if the original fails |
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.
Why do we need this? Could we always add a function defined here so we don't have to rely on typing._type_check?
src/test_typing_extensions.py
Outdated
assert Y.__name__ not in globals() | ||
|
||
minimal_locals = { | ||
#"Y": Y, |
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.
remove?
src/test_typing_extensions.py
Outdated
@@ -8098,6 +8100,563 @@ def test_pep_695_generics_with_future_annotations_nested_in_function(self): | |||
set(results.generic_func.__type_params__) | |||
) | |||
|
|||
class TestEvaluateForwardRefs(BaseTestCase): | |||
def test_evaluate_forward_refs(self): | |||
from typing import ForwardRef # noqa: F401 # needed for locals |
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.
Do we really need this? Better to pass an explicit namespace instead of relying on the locals of this function.
src/test_typing_extensions.py
Outdated
localns, | ||
type_params, | ||
owner, | ||
) in unroll_cases(cases, locals()): |
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.
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.
See PEP 749
…rd_ref' into 3.14/evaluate_forward_ref
Backports
evaluate_forward_ref
from JelleZijlstra's PR python/cpython#119891 / PEP 749.The most tricky part seems to be in recursive
ForwardRef
s, 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