diff --git a/astroid/brain/brain_typing.py b/astroid/brain/brain_typing.py index 9ff72274dd..599ad79f94 100644 --- a/astroid/brain/brain_typing.py +++ b/astroid/brain/brain_typing.py @@ -82,7 +82,10 @@ def infer_typing_attr(node, context=None): if not value.qname().startswith("typing."): raise UseInferenceDefault - node = extract_node(TYPING_TYPE_TEMPLATE.format(value.qname().split(".")[-1])) + node = extract_node( + TYPING_TYPE_TEMPLATE.format(value.qname().split(".")[-1]), + "typing" + ) return node.infer(context=context) diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py index cb11c4cf4e..30e17d4c09 100644 --- a/tests/unittest_brain.py +++ b/tests/unittest_brain.py @@ -1080,6 +1080,17 @@ def test_typing_namedtuple_dont_crash_on_no_fields(self): inferred = next(node.infer()) self.assertIsInstance(inferred, astroid.Instance) + def test_generic_subscript(self): + node = builder.extract_node( + """ + from typing import Generic, TypeVar + T = TypeVar('T') + Generic[T] #@ + """ + ) + inferred = next(node.infer()) + self.assertEqual(inferred.qname(), "typing.Generic") + class ReBrainTest(unittest.TestCase): def test_regex_flags(self):