From 17b5ed0a0123d16675472c908136146d83a3a8f0 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 17 Jan 2022 18:23:20 +0300 Subject: [PATCH 1/2] bpo-46416: fix direct invocation of `Lib/test/test_typing.py` --- Lib/test/test_typing.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index c8a077e2f1ff55..6cc8411875fa29 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -43,6 +43,8 @@ py_typing = import_helper.import_fresh_module('typing', blocked=['_typing']) c_typing = import_helper.import_fresh_module('typing', fresh=['_typing']) +MODULE = ('test.test_typing', '__main__')[__name__ == '__main__'] + class BaseTestCase(TestCase): @@ -5067,7 +5069,7 @@ def test_special_attrs2(self): ) self.assertEqual( SpecialAttrsTests.TypeName.__module__, - 'test.test_typing', + MODULE, ) # NewTypes are picklable assuming correct qualname information. for proto in range(pickle.HIGHEST_PROTOCOL + 1): @@ -5081,7 +5083,7 @@ def test_special_attrs2(self): # __qualname__ is unnecessary. self.assertEqual(SpecialAttrsT.__name__, 'SpecialAttrsT') self.assertFalse(hasattr(SpecialAttrsT, '__qualname__')) - self.assertEqual(SpecialAttrsT.__module__, 'test.test_typing') + self.assertEqual(SpecialAttrsT.__module__, MODULE) # Module-level type variables are picklable. for proto in range(pickle.HIGHEST_PROTOCOL + 1): s = pickle.dumps(SpecialAttrsT, proto) @@ -5090,7 +5092,7 @@ def test_special_attrs2(self): self.assertEqual(SpecialAttrsP.__name__, 'SpecialAttrsP') self.assertFalse(hasattr(SpecialAttrsP, '__qualname__')) - self.assertEqual(SpecialAttrsP.__module__, 'test.test_typing') + self.assertEqual(SpecialAttrsP.__module__, MODULE) # Module-level ParamSpecs are picklable. for proto in range(pickle.HIGHEST_PROTOCOL + 1): s = pickle.dumps(SpecialAttrsP, proto) From bb535175011323b8652a201941fa73f48998cfe6 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 17 Jan 2022 21:22:55 +0300 Subject: [PATCH 2/2] Use `__name__` --- Lib/test/test_typing.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 6cc8411875fa29..984c9528443fa5 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -43,8 +43,6 @@ py_typing = import_helper.import_fresh_module('typing', blocked=['_typing']) c_typing = import_helper.import_fresh_module('typing', fresh=['_typing']) -MODULE = ('test.test_typing', '__main__')[__name__ == '__main__'] - class BaseTestCase(TestCase): @@ -5069,7 +5067,7 @@ def test_special_attrs2(self): ) self.assertEqual( SpecialAttrsTests.TypeName.__module__, - MODULE, + __name__, ) # NewTypes are picklable assuming correct qualname information. for proto in range(pickle.HIGHEST_PROTOCOL + 1): @@ -5083,7 +5081,7 @@ def test_special_attrs2(self): # __qualname__ is unnecessary. self.assertEqual(SpecialAttrsT.__name__, 'SpecialAttrsT') self.assertFalse(hasattr(SpecialAttrsT, '__qualname__')) - self.assertEqual(SpecialAttrsT.__module__, MODULE) + self.assertEqual(SpecialAttrsT.__module__, __name__) # Module-level type variables are picklable. for proto in range(pickle.HIGHEST_PROTOCOL + 1): s = pickle.dumps(SpecialAttrsT, proto) @@ -5092,7 +5090,7 @@ def test_special_attrs2(self): self.assertEqual(SpecialAttrsP.__name__, 'SpecialAttrsP') self.assertFalse(hasattr(SpecialAttrsP, '__qualname__')) - self.assertEqual(SpecialAttrsP.__module__, MODULE) + self.assertEqual(SpecialAttrsP.__module__, __name__) # Module-level ParamSpecs are picklable. for proto in range(pickle.HIGHEST_PROTOCOL + 1): s = pickle.dumps(SpecialAttrsP, proto)