diff options
author | will-ca <willchencontact@gmail.com> | 2021-06-26 23:31:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-26 23:31:32 (GMT) |
commit | 7569c0fe91dfcf562dee8c29798ecda74d738aa8 (patch) | |
tree | 3561e803ea17399dc8347028cd6fdc4e3ef860d5 /Lib/test/test_typing.py | |
parent | 521ba8892ef367c45bf1647b04a726d3f553637c (diff) | |
download | cpython-7569c0fe91dfcf562dee8c29798ecda74d738aa8.zip cpython-7569c0fe91dfcf562dee8c29798ecda74d738aa8.tar.gz cpython-7569c0fe91dfcf562dee8c29798ecda74d738aa8.tar.bz2 |
bpo-44468: Never skip base classes in `typing.get_type_hints()`, even with invalid `.__module__`. (GH-26862)
Diffstat (limited to 'Lib/test/test_typing.py')
-rw-r--r-- | Lib/test/test_typing.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index cb198d6..e693883 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -2277,13 +2277,6 @@ class ClassVarTests(BaseTestCase): with self.assertRaises(TypeError): issubclass(int, ClassVar) - def test_bad_module(self): - # bpo-41515 - class BadModule: - pass - BadModule.__module__ = 'bad' # Something not in sys.modules - self.assertEqual(get_type_hints(BadModule), {}) - class FinalTests(BaseTestCase): def test_basics(self): @@ -3033,6 +3026,24 @@ class GetTypeHintTests(BaseTestCase): # This previously raised an error under PEP 563. self.assertEqual(get_type_hints(Foo), {'x': str}) + def test_get_type_hints_bad_module(self): + # bpo-41515 + class BadModule: + pass + BadModule.__module__ = 'bad' # Something not in sys.modules + self.assertNotIn('bad', sys.modules) + self.assertEqual(get_type_hints(BadModule), {}) + + def test_get_type_hints_annotated_bad_module(self): + # See https://bugs.python.org/issue44468 + class BadBase: + foo: tuple + class BadType(BadBase): + bar: list + BadType.__module__ = BadBase.__module__ = 'bad' + self.assertNotIn('bad', sys.modules) + self.assertEqual(get_type_hints(BadType), {'foo': tuple, 'bar': list}) + class GetUtilitiesTestCase(TestCase): def test_get_origin(self): |