forked from VimPlug/jedi
Fix most of PEP 484.
This commit is contained in:
@@ -72,12 +72,14 @@ class ParamName(ContextName):
|
||||
|
||||
def _get_param(self):
|
||||
params = self.parent_context.get_params()
|
||||
return params[self.tree_name.parent.position_nr]
|
||||
param_node = search_ancestor(self.tree_name, 'param')
|
||||
return params[param_node.position_nr]
|
||||
|
||||
|
||||
class AnonymousInstanceParamName(ParamName):
|
||||
def infer(self):
|
||||
if self.tree_name.parent.position_nr == 0:
|
||||
param_node = search_ancestor(self.tree_name, 'param')
|
||||
if param_node.position_nr == 0:
|
||||
# This is a speed optimization, to return the self param (because
|
||||
# it's known). This only affects anonymous instances.
|
||||
return set([self.parent_context.instance])
|
||||
|
||||
@@ -324,6 +324,31 @@ class SelfNameFilter(InstanceClassFilter):
|
||||
yield name
|
||||
|
||||
|
||||
class ParamArguments(object):
|
||||
"""
|
||||
TODO This seems like a strange class, clean up?
|
||||
"""
|
||||
class LazyParamContext(object):
|
||||
def __init__(self, fucking_param):
|
||||
self._param = fucking_param
|
||||
|
||||
def infer(self):
|
||||
return self._param.infer()
|
||||
|
||||
def __init__(self, class_context, funcdef):
|
||||
self._class_context = class_context
|
||||
self._funcdef = funcdef
|
||||
|
||||
def unpack(self, func=None):
|
||||
params = search_params(
|
||||
self._class_context.evaluator,
|
||||
self._class_context,
|
||||
self._funcdef
|
||||
)
|
||||
for p in params:
|
||||
yield None, self.LazyParamContext(p)
|
||||
|
||||
|
||||
class InstanceVarArgs(object):
|
||||
def __init__(self, instance, funcdef, var_args):
|
||||
self._instance = instance
|
||||
@@ -334,11 +359,8 @@ class InstanceVarArgs(object):
|
||||
def _get_var_args(self):
|
||||
if self._var_args is None:
|
||||
# TODO this parent_context might be wrong. test?!
|
||||
return search_params(
|
||||
self._instance.evaluator,
|
||||
self._instance.class_context,
|
||||
self._funcdef
|
||||
)
|
||||
return ParamArguments(self._instance.class_context, self._funcdef)
|
||||
|
||||
return self._var_args
|
||||
|
||||
def unpack(self, func=None):
|
||||
|
||||
@@ -8,6 +8,7 @@ from jedi.evaluate import iterable
|
||||
from jedi.evaluate import analysis
|
||||
from jedi.evaluate import context
|
||||
from jedi.evaluate import docstrings
|
||||
from jedi.evaluate import pep0484
|
||||
|
||||
|
||||
def try_iter_content(types, depth=0):
|
||||
@@ -184,7 +185,7 @@ class ExecutedParam(object):
|
||||
self.string_name = self._original_param.name.value
|
||||
|
||||
def infer(self):
|
||||
pep0484_hints = set()#pep0484.follow_param(evaluator, param)
|
||||
pep0484_hints = pep0484.follow_param(self._root_context, self._original_param)
|
||||
doc_params = docstrings.follow_param(self._root_context, self._original_param)
|
||||
if pep0484_hints or doc_params:
|
||||
return list(set(pep0484_hints) | set(doc_params))
|
||||
|
||||
@@ -77,8 +77,8 @@ def _fix_forward_reference(context, node):
|
||||
return node
|
||||
|
||||
|
||||
@memoize_default(None, evaluator_is_first_arg=True)
|
||||
def follow_param(evaluator, param):
|
||||
@memoize_default()
|
||||
def follow_param(context, param):
|
||||
annotation = param.annotation()
|
||||
return _evaluate_for_annotation(context, annotation)
|
||||
|
||||
@@ -96,7 +96,7 @@ def py__annotations__(funcdef):
|
||||
return dct
|
||||
|
||||
|
||||
@memoize_default(None, evaluator_is_first_arg=True)
|
||||
@memoize_default()
|
||||
def find_return_types(context, func):
|
||||
annotation = py__annotations__(func).get("return", None)
|
||||
return _evaluate_for_annotation(context, annotation)
|
||||
|
||||
@@ -644,7 +644,7 @@ class FunctionExecutionContext(Executed):
|
||||
else:
|
||||
returns = funcdef.returns
|
||||
types = set(docstrings.find_return_types(self.get_root_context(), funcdef))
|
||||
types |= set(pep0484.find_return_types(self.evaluator, funcdef))
|
||||
types |= set(pep0484.find_return_types(self.get_root_context(), funcdef))
|
||||
|
||||
for r in returns:
|
||||
check = flow_analysis.reachability_check(self, funcdef, r)
|
||||
|
||||
Reference in New Issue
Block a user