diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/pep0484.py index b9008a94..2c2cb173 100644 --- a/jedi/evaluate/pep0484.py +++ b/jedi/evaluate/pep0484.py @@ -17,13 +17,23 @@ x support `@no_type_check` and `@no_type_check_decorator` """ from itertools import chain - +from jedi.parser import Parser, load_grammar from jedi.evaluate.cache import memoize_default +from jedi.evaluate.compiled import CompiledObject def _evaluate_for_annotation(evaluator, annotation): if annotation is not None: - definitions = evaluator.eval_element(annotation) + definitions = set() + for definition in evaluator.eval_element(annotation): + if (isinstance(definition, CompiledObject) and + isinstance(definition.obj, str)): + p = Parser(load_grammar(), definition.obj) + element = p.module.children[0].children[0] + element.parent = annotation.parent + definitions |= evaluator.eval_element(element) + else: + definitions.add(definition) return list(chain.from_iterable( evaluator.execute(d) for d in definitions)) else: diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index a20030cb..2951722c 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -41,7 +41,6 @@ import textwrap from jedi._compatibility import (Python3Method, encoding, is_py3, utf8_repr, literal_eval, use_metaclass, unicode) from jedi import cache -import ast def is_node(node, *symbol_names): @@ -53,19 +52,6 @@ def is_node(node, *symbol_names): return type in symbol_names -def _fix_forward_reference(annotation): - if isinstance(annotation, String): - newannotation = Name( - annotation.position_modifier, - ast.literal_eval(annotation.value), - annotation.start_pos, - annotation.prefix) - newannotation.parent = annotation.parent - else: - newannotation = annotation - return newannotation - - class PositionModifier(object): """A start_pos modifier for the fast parser.""" def __init__(self): @@ -881,8 +867,9 @@ class Function(ClassOrFunc): def annotation(self): try: if self.children[3] == "->": - return _fix_forward_reference(self.children[4]) + return self.children[4] assert self.children[3] == ":" + return None except IndexError: return None @@ -1428,7 +1415,7 @@ class Param(BaseNode): assert tfpdef.children[1] == ":" assert len(tfpdef.children) == 3 annotation = tfpdef.children[2] - return _fix_forward_reference(annotation) + return annotation else: return None