@@ -6230,6 +6230,47 @@ def test_is_param_expr(self):
62306230 self .assertTrue (typing ._is_param_expr (concat ))
62316231 self .assertTrue (typing ._is_param_expr (typing_concat ))
62326232
6233+ def test_isinstance_results_unaffected_by_presence_of_tracing_function (self ):
6234+ # See https://github.com/python/typing_extensions/issues/661
6235+
6236+ code = textwrap .dedent (
6237+ """\
6238+ import sys, typing
6239+
6240+ def trace_call(*args):
6241+ return trace_call
6242+
6243+ def run():
6244+ sys.modules.pop("typing_extensions", None)
6245+ from typing_extensions import Concatenate
6246+ return isinstance(Concatenate[...], typing._GenericAlias)
6247+ isinstance_result_1 = run()
6248+ sys.setprofile(trace_call)
6249+ isinstance_result_2 = run()
6250+ sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}")
6251+ """
6252+ )
6253+
6254+ # Run this in an isolated process or it pollutes the environment
6255+ # and makes other tests fail:
6256+ try :
6257+ proc = subprocess .run (
6258+ [sys .executable , "-c" , code ], check = True , capture_output = True , text = True ,
6259+ )
6260+ except subprocess .CalledProcessError as exc :
6261+ print ("stdout" , exc .stdout , sep = "\n " )
6262+ print ("stderr" , exc .stderr , sep = "\n " )
6263+ raise
6264+
6265+ # Sanity checks that assert the test is working as expected
6266+ self .assertIsInstance (proc .stdout , str )
6267+ result1 , result2 = proc .stdout .split (" " )
6268+ self .assertIn (result1 , {"True" , "False" })
6269+ self .assertIn (result2 , {"True" , "False" })
6270+
6271+ # The actual test:
6272+ self .assertEqual (result1 , result2 )
6273+
62336274class TypeGuardTests (BaseTestCase ):
62346275 def test_basics (self ):
62356276 TypeGuard [int ] # OK
@@ -6652,6 +6693,46 @@ def test_type_var_inheritance(self):
66526693 self .assertFalse (isinstance (Unpack [Ts ], TypeVar ))
66536694 self .assertFalse (isinstance (Unpack [Ts ], typing .TypeVar ))
66546695
6696+ def test_isinstance_results_unaffected_by_presence_of_tracing_function (self ):
6697+ # See https://github.com/python/typing_extensions/issues/661
6698+
6699+ code = textwrap .dedent (
6700+ """\
6701+ import sys, typing
6702+
6703+ def trace_call(*args):
6704+ return trace_call
6705+
6706+ def run():
6707+ sys.modules.pop("typing_extensions", None)
6708+ from typing_extensions import TypeVarTuple, Unpack
6709+ return isinstance(Unpack[TypeVarTuple("Ts")], typing.TypeVar)
6710+ isinstance_result_1 = run()
6711+ sys.setprofile(trace_call)
6712+ isinstance_result_2 = run()
6713+ sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}")
6714+ """
6715+ )
6716+
6717+ # Run this in an isolated process or it pollutes the environment
6718+ # and makes other tests fail:
6719+ try :
6720+ proc = subprocess .run (
6721+ [sys .executable , "-c" , code ], check = True , capture_output = True , text = True ,
6722+ )
6723+ except subprocess .CalledProcessError as exc :
6724+ print ("stdout" , exc .stdout , sep = "\n " )
6725+ print ("stderr" , exc .stderr , sep = "\n " )
6726+ raise
6727+
6728+ # Sanity checks that assert the test is working as expected
6729+ self .assertIsInstance (proc .stdout , str )
6730+ result1 , result2 = proc .stdout .split (" " )
6731+ self .assertIn (result1 , {"True" , "False" })
6732+ self .assertIn (result2 , {"True" , "False" })
6733+
6734+ # The actual test:
6735+ self .assertEqual (result1 , result2 )
66556736
66566737class TypeVarTupleTests (BaseTestCase ):
66576738
0 commit comments