@@ -5020,6 +5020,48 @@ def test_eq(self):
50205020 # won't be the same.
50215021 self .assertNotEqual (hash (ParamSpec ('P' )), hash (P ))
50225022
5023+ def test_isinstance_results_unaffected_by_presence_of_tracing_function (self ):
5024+ # See https://github.com/python/typing_extensions/issues/318
5025+
5026+ code = textwrap .dedent (
5027+ """\
5028+ import sys, typing
5029+
5030+ def trace_call(*args):
5031+ return trace_call
5032+
5033+ def run():
5034+ sys.modules.pop("typing_extensions", None)
5035+ from typing_extensions import ParamSpec
5036+ return isinstance(ParamSpec("P"), typing.TypeVar)
5037+
5038+ isinstance_result_1 = run()
5039+ sys.setprofile(trace_call)
5040+ isinstance_result_2 = run()
5041+ sys.stdout.write(f"{isinstance_result_1} {isinstance_result_2}")
5042+ """
5043+ )
5044+
5045+ # Run this in an isolated process or it pollutes the environment
5046+ # and makes other tests fail:
5047+ try :
5048+ proc = subprocess .run (
5049+ [sys .executable , "-c" , code ], check = True , capture_output = True , text = True ,
5050+ )
5051+ except subprocess .CalledProcessError as exc :
5052+ print ("stdout" , exc .stdout , sep = "\n " )
5053+ print ("stderr" , exc .stderr , sep = "\n " )
5054+ raise
5055+
5056+ # Sanity checks that assert the test is working as expected
5057+ self .assertIsInstance (proc .stdout , str )
5058+ result1 , result2 = proc .stdout .split (" " )
5059+ self .assertIn (result1 , {"True" , "False" })
5060+ self .assertIn (result2 , {"True" , "False" })
5061+
5062+ # The actual test:
5063+ self .assertEqual (result1 , result2 )
5064+
50235065
50245066class ConcatenateTests (BaseTestCase ):
50255067 def test_basics (self ):
0 commit comments