1
0
forked from VimPlug/jedi

Move annotation pep0484 file (about anontations) to gradual folder

This commit is contained in:
Dave Halter
2018-12-24 17:48:21 +01:00
parent e2ab4c060f
commit 59c7623769
7 changed files with 19 additions and 18 deletions

View File

@@ -6,7 +6,6 @@ from jedi.evaluate.cache import evaluator_method_cache, CachedMetaClass
from jedi.evaluate import compiled from jedi.evaluate import compiled
from jedi.evaluate import recursion from jedi.evaluate import recursion
from jedi.evaluate import docstrings from jedi.evaluate import docstrings
from jedi.evaluate import pep0484
from jedi.evaluate import flow_analysis from jedi.evaluate import flow_analysis
from jedi.evaluate import helpers from jedi.evaluate import helpers
from jedi.evaluate.signature import TreeSignature 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.evaluate.context import iterable
from jedi import parser_utils from jedi import parser_utils
from jedi.evaluate.parser_cache import get_yield_exprs from jedi.evaluate.parser_cache import get_yield_exprs
from jedi.evaluate.gradual.annotation import infer_return_types
class LambdaName(AbstractNameDefinition): class LambdaName(AbstractNameDefinition):
@@ -179,7 +179,7 @@ class FunctionExecutionContext(TreeContext):
returns = get_yield_exprs(self.evaluator, funcdef) returns = get_yield_exprs(self.evaluator, funcdef)
else: else:
returns = funcdef.iter_return_stmts() returns = funcdef.iter_return_stmts()
context_set = pep0484.infer_return_types(self) context_set = infer_return_types(self)
if context_set: if context_set:
# If there are annotations, prefer them over anything else. # If there are annotations, prefer them over anything else.
# This will make it faster. # This will make it faster.

View File

@@ -273,7 +273,8 @@ class TreeInstance(AbstractInstanceContext):
# to itself. # to itself.
@evaluator_method_cache(default=None) @evaluator_method_cache(default=None)
def _get_annotated_class_object(self): 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(): for func in self._get_annotation_init_functions():
# Just take the first result, it should always be one, because we # Just take the first result, it should always be one, because we
@@ -285,9 +286,9 @@ class TreeInstance(AbstractInstanceContext):
# need to infer anything. # need to infer anything.
continue continue
all_annotations = pep0484.py__annotations__(execution.tree_node) all_annotations = py__annotations__(execution.tree_node)
defined = self.class_context.define_generics( 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') debug.dbg('Inferred instance context as %s', defined, color='BLUE')
return defined return defined

View File

@@ -228,7 +228,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
if stars: if stars:
continue # These are not relevant for this search. 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): for type_var in find_unknown_type_vars(self.parent_context, node):
if type_var not in found: if type_var not in found:
# The order matters and it's therefore a list. # The order matters and it's therefore a list.

View File

@@ -224,7 +224,7 @@ def _iter_over_arguments(maybe_tuple_context, defining_context):
def resolve_forward_references(context_set): def resolve_forward_references(context_set):
for context in context_set: for context in context_set:
if is_string(context): 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()) node = _get_forward_reference_node(defining_context, context.get_safe_value())
if node is not None: if node is not None:
for c in defining_context.eval_node(node): for c in defining_context.eval_node(node):

View File

@@ -27,8 +27,8 @@ class ExecutedParam(object):
self._is_default = is_default self._is_default = is_default
def infer_annotations(self): def infer_annotations(self):
from jedi.evaluate import pep0484 from jedi.evaluate.gradual.annotation import infer_param
return pep0484.infer_param(self._execution_context, self._param_node) return infer_param(self._execution_context, self._param_node)
def infer(self, use_hints=True): def infer(self, use_hints=True):
if use_hints: if use_hints:

View File

@@ -12,7 +12,6 @@ from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, ContextualizedNo
ContextualizedName, iterator_to_context_set, iterate_contexts ContextualizedName, iterator_to_context_set, iterate_contexts
from jedi.evaluate.lazy_context import LazyTreeContext from jedi.evaluate.lazy_context import LazyTreeContext
from jedi.evaluate import compiled from jedi.evaluate import compiled
from jedi.evaluate import pep0484
from jedi.evaluate import recursion from jedi.evaluate import recursion
from jedi.evaluate import helpers from jedi.evaluate import helpers
from jedi.evaluate import analysis 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.compiled.access import COMPARISON_OPERATORS
from jedi.evaluate.cache import evaluator_method_cache from jedi.evaluate.cache import evaluator_method_cache
from jedi.evaluate.gradual.typeshed import VersionInfo from jedi.evaluate.gradual.typeshed import VersionInfo
from jedi.evaluate.gradual import annotation
def _limit_context_infers(func): def _limit_context_infers(func):
@@ -133,7 +133,7 @@ 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.eval_annotation(context, element.children[1]) \ return annotation.eval_annotation(context, element.children[1]) \
.execute_annotation() .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':
@@ -417,9 +417,9 @@ def _is_annotation_name(name):
return False return False
if ancestor.type in ('param', 'funcdef'): if ancestor.type in ('param', 'funcdef'):
annotation = ancestor.annotation ann = ancestor.annotation
if annotation is not None: if ann is not None:
return annotation.start_pos <= name.start_pos < annotation.end_pos return ann.start_pos <= name.start_pos < ann.end_pos
elif ancestor.type == 'expr_stmt': elif ancestor.type == 'expr_stmt':
c = ancestor.children c = ancestor.children
if len(c) > 1 and c[1].type == 'annassign': if len(c) > 1 and c[1].type == 'annassign':
@@ -534,7 +534,7 @@ def _remove_statements(evaluator, context, stmt, name):
evaluated. evaluated.
""" """
pep0484_contexts = \ 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: if pep0484_contexts:
return 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": if expr_stmt.type == "expr_stmt" and expr_stmt.children[1].type == "annassign":
correct_scope = parser_utils.get_parent_scope(name) == context.tree_node correct_scope = parser_utils.get_parent_scope(name) == context.tree_node
if correct_scope: if correct_scope:
context_set |= pep0484.eval_annotation( context_set |= annotation.eval_annotation(
context, expr_stmt.children[1].children[1] context, expr_stmt.children[1].children[1]
).execute_annotation() ).execute_annotation()
if context_set: if context_set:
@@ -576,11 +576,11 @@ def tree_name_to_contexts(evaluator, context, tree_name):
typ = node.type typ = node.type
if typ == 'for_stmt': 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: if types:
return types return types
if typ == 'with_stmt': 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: if types:
return types return types