-
-
Notifications
You must be signed in to change notification settings - Fork 136
Ensure isinstance is unaffected by sys.setprofile for Concatenate[] and Unpack[] aliases; run PyPy tests under coverage
#668
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
Changes from 7 commits
4e955b9
71b62ca
7b5c54d
6f51d63
af837be
c161d40
04d7e20
bb8a5bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6230,6 +6230,47 @@ def test_is_param_expr(self): | |
| self.assertTrue(typing._is_param_expr(concat)) | ||
| self.assertTrue(typing._is_param_expr(typing_concat)) | ||
|
|
||
| def test_isinstance_results_unaffected_by_presence_of_tracing_function(self): | ||
| # See https://github.com/python/typing_extensions/issues/661 | ||
|
|
||
| code = textwrap.dedent( | ||
| """\ | ||
| import sys, typing | ||
|
|
||
| def trace_call(*args): | ||
| return trace_call | ||
|
Comment on lines
+6240
to
+6241
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curiously, if the trace function accesses def trace_call(frame, event, arg):
frame.f_locals
return trace_callthen the test fails on Python 3.12.0 (and only this version) with this odd error: /home/runner/work/typing_extensions/typing_extensions/src/typing_extensions.py:4303: RuntimeWarning: assigning None to unbound local 'name'
{name: getattr(typing, name) for name in _typing_names if hasattr(typing, name)}
Traceback (most recent call last):
File "<string>", line 13, in <module>
File "<string>", line 9, in run
File "/home/runner/work/typing_extensions/typing_extensions/src/typing_extensions.py", line 4303, in <module>
{name: getattr(typing, name) for name in _typing_names if hasattr(typing, name)}
^^^^^^^^^^^^^^^^^^^^^
TypeError: attribute name must be string, not 'NoneType'https://github.com/brianschubert/typing_extensions/actions/runs/17386017836/job/49352484071?pr=5 Note that it only fails on the 3.12.0 tests, not the 3.12 tests (which pass). The same is true for the existing test in |
||
|
|
||
| def run(): | ||
| sys.modules.pop("typing_extensions", None) | ||
| from typing_extensions import Concatenate | ||
| return isinstance(Concatenate[...], typing._GenericAlias) | ||
| isinstance_result_1 = run() | ||
| sys.setprofile(trace_call) | ||
| isinstance_result_2 = run() | ||
| sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}") | ||
| """ | ||
| ) | ||
|
|
||
| # Run this in an isolated process or it pollutes the environment | ||
| # and makes other tests fail: | ||
| try: | ||
| proc = subprocess.run( | ||
| [sys.executable, "-c", code], check=True, capture_output=True, text=True, | ||
| ) | ||
| except subprocess.CalledProcessError as exc: | ||
| print("stdout", exc.stdout, sep="\n") | ||
| print("stderr", exc.stderr, sep="\n") | ||
| raise | ||
|
|
||
| # Sanity checks that assert the test is working as expected | ||
| self.assertIsInstance(proc.stdout, str) | ||
| result1, result2 = proc.stdout.split(" ") | ||
| self.assertIn(result1, {"True", "False"}) | ||
| self.assertIn(result2, {"True", "False"}) | ||
|
|
||
| # The actual test: | ||
| self.assertEqual(result1, result2) | ||
|
|
||
| class TypeGuardTests(BaseTestCase): | ||
| def test_basics(self): | ||
| TypeGuard[int] # OK | ||
|
|
@@ -6652,6 +6693,46 @@ def test_type_var_inheritance(self): | |
| self.assertFalse(isinstance(Unpack[Ts], TypeVar)) | ||
| self.assertFalse(isinstance(Unpack[Ts], typing.TypeVar)) | ||
|
|
||
| def test_isinstance_results_unaffected_by_presence_of_tracing_function(self): | ||
| # See https://github.com/python/typing_extensions/issues/661 | ||
|
|
||
| code = textwrap.dedent( | ||
| """\ | ||
| import sys, typing | ||
|
|
||
| def trace_call(*args): | ||
| return trace_call | ||
|
|
||
| def run(): | ||
| sys.modules.pop("typing_extensions", None) | ||
| from typing_extensions import TypeVarTuple, Unpack | ||
| return isinstance(Unpack[TypeVarTuple("Ts")], typing.TypeVar) | ||
| isinstance_result_1 = run() | ||
| sys.setprofile(trace_call) | ||
| isinstance_result_2 = run() | ||
| sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}") | ||
| """ | ||
| ) | ||
|
|
||
| # Run this in an isolated process or it pollutes the environment | ||
| # and makes other tests fail: | ||
| try: | ||
| proc = subprocess.run( | ||
| [sys.executable, "-c", code], check=True, capture_output=True, text=True, | ||
| ) | ||
| except subprocess.CalledProcessError as exc: | ||
| print("stdout", exc.stdout, sep="\n") | ||
| print("stderr", exc.stderr, sep="\n") | ||
| raise | ||
|
|
||
| # Sanity checks that assert the test is working as expected | ||
| self.assertIsInstance(proc.stdout, str) | ||
| result1, result2 = proc.stdout.split(" ") | ||
| self.assertIn(result1, {"True", "False"}) | ||
| self.assertIn(result2, {"True", "False"}) | ||
|
|
||
| # The actual test: | ||
| self.assertEqual(result1, result2) | ||
|
|
||
| class TypeVarTupleTests(BaseTestCase): | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.