mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Get a first typing test with Sequence[int] working
This means basically that annotations are working at least in some way and Generic classes as well.
This commit is contained in:
@@ -123,12 +123,18 @@ class FunctionContext(use_metaclass(CachedMetaClass, AbstractFunction)):
|
|||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return compiled.get_special_object(self.evaluator, u'FUNCTION_CLASS')
|
return compiled.get_special_object(self.evaluator, u'FUNCTION_CLASS')
|
||||||
|
|
||||||
|
def get_default_param_context(self):
|
||||||
|
return self.parent_context
|
||||||
|
|
||||||
|
|
||||||
class MethodContext(FunctionContext):
|
class MethodContext(FunctionContext):
|
||||||
def __init__(self, evaluator, class_context, *args, **kwargs):
|
def __init__(self, evaluator, class_context, *args, **kwargs):
|
||||||
super(MethodContext, self).__init__(evaluator, *args, **kwargs)
|
super(MethodContext, self).__init__(evaluator, *args, **kwargs)
|
||||||
self.class_context = class_context
|
self.class_context = class_context
|
||||||
|
|
||||||
|
def get_default_param_context(self):
|
||||||
|
return self.class_context
|
||||||
|
|
||||||
|
|
||||||
class FunctionExecutionContext(TreeContext):
|
class FunctionExecutionContext(TreeContext):
|
||||||
"""
|
"""
|
||||||
@@ -192,11 +198,6 @@ class FunctionExecutionContext(TreeContext):
|
|||||||
break
|
break
|
||||||
return context_set
|
return context_set
|
||||||
|
|
||||||
def get_default_param_context(self):
|
|
||||||
if isinstance(self.function_context, MethodContext):
|
|
||||||
return self.function_context.class_context
|
|
||||||
return self.parent_context
|
|
||||||
|
|
||||||
def _get_yield_lazy_context(self, yield_expr):
|
def _get_yield_lazy_context(self, yield_expr):
|
||||||
if yield_expr.type == 'keyword':
|
if yield_expr.type == 'keyword':
|
||||||
# `yield` just yields None.
|
# `yield` just yields None.
|
||||||
|
|||||||
@@ -304,7 +304,7 @@ class TypeVar(Context):
|
|||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self._name)
|
return '<%s: %s>' % (self.__class__.__name__, self.string_name)
|
||||||
|
|
||||||
|
|
||||||
class OverloadFunction(_BaseTypingContext):
|
class OverloadFunction(_BaseTypingContext):
|
||||||
@@ -325,7 +325,7 @@ class BoundTypeVarName(AbstractNameDefinition):
|
|||||||
self._context_set = context_set
|
self._context_set = context_set
|
||||||
|
|
||||||
def infer(self):
|
def infer(self):
|
||||||
return self._context_set.execute_annotation()
|
return self._context_set
|
||||||
|
|
||||||
|
|
||||||
class TypeVarFilter(object):
|
class TypeVarFilter(object):
|
||||||
@@ -378,9 +378,10 @@ class AnnotatedClass(ClassContext):
|
|||||||
|
|
||||||
@evaluator_method_cache()
|
@evaluator_method_cache()
|
||||||
def find_annotation_variables(self):
|
def find_annotation_variables(self):
|
||||||
|
found = []
|
||||||
arglist = self.tree_node.get_super_arglist()
|
arglist = self.tree_node.get_super_arglist()
|
||||||
if arglist is None:
|
if arglist is None:
|
||||||
return
|
return []
|
||||||
|
|
||||||
for stars, node in unpack_arglist(arglist):
|
for stars, node in unpack_arglist(arglist):
|
||||||
if stars:
|
if stars:
|
||||||
@@ -391,8 +392,9 @@ class AnnotatedClass(ClassContext):
|
|||||||
if trailer.type == 'trailer' and trailer.children[0] == '[':
|
if trailer.type == 'trailer' and trailer.children[0] == '[':
|
||||||
type_var_set = self.parent_context.eval_node(trailer.children[1])
|
type_var_set = self.parent_context.eval_node(trailer.children[1])
|
||||||
for type_var in type_var_set:
|
for type_var in type_var_set:
|
||||||
if isinstance(type_var, TypeVar):
|
if isinstance(type_var, TypeVar) and type_var not in found:
|
||||||
yield type_var
|
found.append(type_var)
|
||||||
|
return found
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s[%s]>' % (
|
return '<%s: %s[%s]>' % (
|
||||||
|
|||||||
@@ -168,10 +168,11 @@ def infer_param(execution_context, param):
|
|||||||
|
|
||||||
param_comment = params_comments[index]
|
param_comment = params_comments[index]
|
||||||
return _evaluate_annotation_string(
|
return _evaluate_annotation_string(
|
||||||
execution_context.get_root_context(),
|
execution_context.function_context.get_default_param_context(),
|
||||||
param_comment
|
param_comment
|
||||||
)
|
)
|
||||||
module_context = execution_context.get_root_context()
|
# Annotations are like default params and resolve in the same way.
|
||||||
|
module_context = execution_context.function_context.get_default_param_context()
|
||||||
return _evaluate_for_annotation(module_context, annotation)
|
return _evaluate_for_annotation(module_context, annotation)
|
||||||
|
|
||||||
|
|
||||||
@@ -207,11 +208,11 @@ def infer_return_types(function_context):
|
|||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
return _evaluate_annotation_string(
|
return _evaluate_annotation_string(
|
||||||
function_context.get_root_context(),
|
function_context.get_default_param_context(),
|
||||||
match.group(1).strip()
|
match.group(1).strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
module_context = function_context.get_root_context()
|
module_context = function_context.get_default_param_context()
|
||||||
return _evaluate_for_annotation(module_context, annotation)
|
return _evaluate_for_annotation(module_context, annotation)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user