forked from VimPlug/jedi
Move annotation pep0484 file (about anontations) to gradual folder
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user