summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-06-26 16:52:28 -0700
committerGitHub <noreply@github.com>2021-06-26 16:52:28 -0700
commit3df23b5199a4bb237a595cadca6c49d34ab2a56c (patch)
treec34b770ff1bca34ce420df73bb7fbbae11b56ffb /Lib/test
parent6cd369c48f7dbfe4e2c2035011c575b90ad0e7d5 (diff)
downloadcpython-git-3df23b5199a4bb237a595cadca6c49d34ab2a56c.tar.gz
[3.10] bpo-44468: Never skip base classes in `typing.get_type_hints()`, even with invalid `.__module__`. (GH-26862) (GH-26920)
(cherry picked from commit 7569c0fe91dfcf562dee8c29798ecda74d738aa8) Co-authored-by: will-ca <willchencontact@gmail.com> Automerge-Triggered-By: GH:gvanrossum
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index 79c5c3a910..07f809ca30 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -2276,13 +2276,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):
@@ -3032,6 +3025,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):