Fix annotation variables

This commit is contained in:
Dave Halter
2018-09-25 00:33:44 +02:00
parent bdff4e21a8
commit f3b2d49880
2 changed files with 7 additions and 5 deletions

View File

@@ -38,7 +38,7 @@ from jedi import debug
from jedi import parser_utils from jedi import parser_utils
def _evaluate_for_annotation(context, annotation, index=None): def evaluate_for_annotation(context, annotation, index=None):
""" """
Evaluates a string-node, looking for an annotation Evaluates a string-node, looking for an annotation
If index is not None, the annotation is expected to be a tuple If index is not None, the annotation is expected to be a tuple
@@ -174,7 +174,7 @@ def infer_param(execution_context, param):
) )
# Annotations are like default params and resolve in the same way. # Annotations are like default params and resolve in the same way.
context = execution_context.function_context.get_default_param_context() context = execution_context.function_context.get_default_param_context()
return _evaluate_for_annotation(context, annotation) return evaluate_for_annotation(context, annotation)
def py__annotations__(funcdef): def py__annotations__(funcdef):

View File

@@ -17,7 +17,6 @@ from jedi.evaluate import helpers
from jedi.evaluate import analysis from jedi.evaluate import analysis
from jedi.evaluate import imports from jedi.evaluate import imports
from jedi.evaluate import arguments from jedi.evaluate import arguments
from jedi.evaluate.pep0484 import _evaluate_for_annotation
from jedi.evaluate.context import ClassContext, FunctionContext from jedi.evaluate.context import ClassContext, FunctionContext
from jedi.evaluate.context import iterable from jedi.evaluate.context import iterable
from jedi.evaluate.context import TreeInstance, CompiledInstance from jedi.evaluate.context import TreeInstance, CompiledInstance
@@ -131,7 +130,8 @@ def eval_node(context, element):
elif typ == 'eval_input': elif typ == 'eval_input':
return eval_node(context, element.children[0]) return eval_node(context, element.children[0])
elif typ == 'annassign': elif typ == 'annassign':
return pep0484._evaluate_for_annotation(context, element.children[1]) return pep0484.evaluate_for_annotation(context, element.children[1]) \
.execute_annotation()
elif typ == 'yield_expr': elif typ == 'yield_expr':
if len(element.children) and element.children[1].type == 'yield_arg': if len(element.children) and element.children[1].type == 'yield_arg':
# Implies that it's a yield from. # Implies that it's a yield from.
@@ -535,7 +535,9 @@ def tree_name_to_contexts(evaluator, context, tree_name):
correct_scope = parser_utils.get_parent_scope(name) == context.tree_node correct_scope = parser_utils.get_parent_scope(name) == context.tree_node
if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign" and correct_scope: if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign" and correct_scope:
context_set |= _evaluate_for_annotation(context, expr_stmt.children[1].children[1]) context_set |= pep0484.evaluate_for_annotation(
context, expr_stmt.children[1].children[1]
).execute_annotation()
if context_set: if context_set:
return context_set return context_set