From bf6974dabbb75d4e6915b063798f62f86e688fe0 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 30 Aug 2018 01:10:51 +0200 Subject: [PATCH] Fix an issue with a type var lookups --- jedi/evaluate/context/typing.py | 2 +- test/completion/pep0484_typing.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/jedi/evaluate/context/typing.py b/jedi/evaluate/context/typing.py index 7a60a771..34f515e2 100644 --- a/jedi/evaluate/context/typing.py +++ b/jedi/evaluate/context/typing.py @@ -479,7 +479,7 @@ class _AbstractAnnotatedClass(ClassContext): continue # These are not relevant for this search. if node.type == 'atom_expr': - trailer = node.children[1] + trailer = node.children[-1] if trailer.type == 'trailer' and trailer.children[0] == '[': for subscript_node in self._unpack_subscriptlist(trailer.children[1]): type_var_set = self.parent_context.eval_node(subscript_node) diff --git a/test/completion/pep0484_typing.py b/test/completion/pep0484_typing.py index 5d58c1f0..1dc633aa 100644 --- a/test/completion/pep0484_typing.py +++ b/test/completion/pep0484_typing.py @@ -305,3 +305,16 @@ from typing import Union as U def union4(x: U[int, str]): #? int() str() x + + +TYPE_VAR = typing.TypeVar('TYPE_VAR') + + +class WithTypeVar(typing.Generic[TYPE_VAR]): + def lala(self) -> TYPE_VAR: + ... + + +def maaan(p: WithTypeVar[int]): + #? int() + p.lala()