From 59c7623769680db818d39f110326d96b60664e59 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Mon, 24 Dec 2018 17:48:21 +0100 Subject: [PATCH] Move annotation pep0484 file (about anontations) to gradual folder --- jedi/evaluate/context/function.py | 4 ++-- jedi/evaluate/context/instance.py | 7 ++++--- jedi/evaluate/context/klass.py | 2 +- .../{pep0484.py => gradual/annotation.py} | 0 jedi/evaluate/gradual/typing.py | 2 +- jedi/evaluate/param.py | 4 ++-- jedi/evaluate/syntax_tree.py | 18 +++++++++--------- 7 files changed, 19 insertions(+), 18 deletions(-) rename jedi/evaluate/{pep0484.py => gradual/annotation.py} (100%) diff --git a/jedi/evaluate/context/function.py b/jedi/evaluate/context/function.py index 5f0fc217..8154d599 100644 --- a/jedi/evaluate/context/function.py +++ b/jedi/evaluate/context/function.py @@ -6,7 +6,6 @@ from jedi.evaluate.cache import evaluator_method_cache, CachedMetaClass from jedi.evaluate import compiled from jedi.evaluate import recursion from jedi.evaluate import docstrings -from jedi.evaluate import pep0484 from jedi.evaluate import flow_analysis from jedi.evaluate import helpers from jedi.evaluate.signature import TreeSignature @@ -20,6 +19,7 @@ from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext, \ from jedi.evaluate.context import iterable from jedi import parser_utils from jedi.evaluate.parser_cache import get_yield_exprs +from jedi.evaluate.gradual.annotation import infer_return_types class LambdaName(AbstractNameDefinition): @@ -179,7 +179,7 @@ class FunctionExecutionContext(TreeContext): returns = get_yield_exprs(self.evaluator, funcdef) else: returns = funcdef.iter_return_stmts() - context_set = pep0484.infer_return_types(self) + context_set = infer_return_types(self) if context_set: # If there are annotations, prefer them over anything else. # This will make it faster. diff --git a/jedi/evaluate/context/instance.py b/jedi/evaluate/context/instance.py index 513eedb7..8f5bf0cf 100644 --- a/jedi/evaluate/context/instance.py +++ b/jedi/evaluate/context/instance.py @@ -273,7 +273,8 @@ class TreeInstance(AbstractInstanceContext): # to itself. @evaluator_method_cache(default=None) def _get_annotated_class_object(self): - from jedi.evaluate import pep0484 + from jedi.evaluate.gradual.annotation import py__annotations__, \ + infer_type_vars_for_execution for func in self._get_annotation_init_functions(): # Just take the first result, it should always be one, because we @@ -285,9 +286,9 @@ class TreeInstance(AbstractInstanceContext): # need to infer anything. continue - all_annotations = pep0484.py__annotations__(execution.tree_node) + all_annotations = py__annotations__(execution.tree_node) defined = self.class_context.define_generics( - pep0484.infer_type_vars_for_execution(execution, all_annotations), + infer_type_vars_for_execution(execution, all_annotations), ) debug.dbg('Inferred instance context as %s', defined, color='BLUE') return defined diff --git a/jedi/evaluate/context/klass.py b/jedi/evaluate/context/klass.py index 5253b5f9..6c571daf 100644 --- a/jedi/evaluate/context/klass.py +++ b/jedi/evaluate/context/klass.py @@ -228,7 +228,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)): if stars: continue # These are not relevant for this search. - from jedi.evaluate.pep0484 import find_unknown_type_vars + from jedi.evaluate.gradual.annotation import find_unknown_type_vars for type_var in find_unknown_type_vars(self.parent_context, node): if type_var not in found: # The order matters and it's therefore a list. diff --git a/jedi/evaluate/pep0484.py b/jedi/evaluate/gradual/annotation.py similarity index 100% rename from jedi/evaluate/pep0484.py rename to jedi/evaluate/gradual/annotation.py diff --git a/jedi/evaluate/gradual/typing.py b/jedi/evaluate/gradual/typing.py index f77459ae..35f8ec43 100644 --- a/jedi/evaluate/gradual/typing.py +++ b/jedi/evaluate/gradual/typing.py @@ -224,7 +224,7 @@ def _iter_over_arguments(maybe_tuple_context, defining_context): def resolve_forward_references(context_set): for context in context_set: if is_string(context): - from jedi.evaluate.pep0484 import _get_forward_reference_node + from jedi.evaluate.gradual.annotation import _get_forward_reference_node node = _get_forward_reference_node(defining_context, context.get_safe_value()) if node is not None: for c in defining_context.eval_node(node): diff --git a/jedi/evaluate/param.py b/jedi/evaluate/param.py index 3e2d5a42..ffec77e3 100644 --- a/jedi/evaluate/param.py +++ b/jedi/evaluate/param.py @@ -27,8 +27,8 @@ class ExecutedParam(object): self._is_default = is_default def infer_annotations(self): - from jedi.evaluate import pep0484 - return pep0484.infer_param(self._execution_context, self._param_node) + from jedi.evaluate.gradual.annotation import infer_param + return infer_param(self._execution_context, self._param_node) def infer(self, use_hints=True): if use_hints: diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index 1f1dbdf8..81593e2e 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -12,7 +12,6 @@ from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, ContextualizedNo ContextualizedName, iterator_to_context_set, iterate_contexts from jedi.evaluate.lazy_context import LazyTreeContext from jedi.evaluate import compiled -from jedi.evaluate import pep0484 from jedi.evaluate import recursion from jedi.evaluate import helpers from jedi.evaluate import analysis @@ -26,6 +25,7 @@ from jedi.evaluate.helpers import is_string, is_literal, is_number, is_compiled from jedi.evaluate.compiled.access import COMPARISON_OPERATORS from jedi.evaluate.cache import evaluator_method_cache from jedi.evaluate.gradual.typeshed import VersionInfo +from jedi.evaluate.gradual import annotation def _limit_context_infers(func): @@ -133,7 +133,7 @@ def eval_node(context, element): elif typ == 'eval_input': return eval_node(context, element.children[0]) elif typ == 'annassign': - return pep0484.eval_annotation(context, element.children[1]) \ + return annotation.eval_annotation(context, element.children[1]) \ .execute_annotation() elif typ == 'yield_expr': if len(element.children) and element.children[1].type == 'yield_arg': @@ -417,9 +417,9 @@ def _is_annotation_name(name): return False if ancestor.type in ('param', 'funcdef'): - annotation = ancestor.annotation - if annotation is not None: - return annotation.start_pos <= name.start_pos < annotation.end_pos + ann = ancestor.annotation + if ann is not None: + return ann.start_pos <= name.start_pos < ann.end_pos elif ancestor.type == 'expr_stmt': c = ancestor.children if len(c) > 1 and c[1].type == 'annassign': @@ -534,7 +534,7 @@ def _remove_statements(evaluator, context, stmt, name): evaluated. """ pep0484_contexts = \ - pep0484.find_type_from_comment_hint_assign(context, stmt, name) + annotation.find_type_from_comment_hint_assign(context, stmt, name) if pep0484_contexts: return pep0484_contexts @@ -553,7 +553,7 @@ def tree_name_to_contexts(evaluator, context, tree_name): if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign": correct_scope = parser_utils.get_parent_scope(name) == context.tree_node if correct_scope: - context_set |= pep0484.eval_annotation( + context_set |= annotation.eval_annotation( context, expr_stmt.children[1].children[1] ).execute_annotation() if context_set: @@ -576,11 +576,11 @@ def tree_name_to_contexts(evaluator, context, tree_name): typ = node.type if typ == 'for_stmt': - types = pep0484.find_type_from_comment_hint_for(context, node, tree_name) + types = annotation.find_type_from_comment_hint_for(context, node, tree_name) if types: return types if typ == 'with_stmt': - types = pep0484.find_type_from_comment_hint_with(context, node, tree_name) + types = annotation.find_type_from_comment_hint_with(context, node, tree_name) if types: return types