forked from VimPlug/jedi
Make sure staticmethod params are (mostly) inferred correctly, fixes #735
This commit is contained in:
@@ -19,6 +19,7 @@ from jedi.inference.value.function import \
|
||||
BaseFunctionExecutionContext, FunctionExecutionContext
|
||||
from jedi.inference.value.klass import ClassFilter
|
||||
from jedi.inference.value.dynamic_arrays import get_dynamic_array_instance
|
||||
from jedi.parser_utils import function_is_static_method
|
||||
|
||||
|
||||
class InstanceExecutedParamName(ParamName):
|
||||
@@ -40,7 +41,8 @@ class AnonymousMethodExecutionFilter(AnonymousFunctionExecutionFilter):
|
||||
self._instance = instance
|
||||
|
||||
def _convert_param(self, param, name):
|
||||
if param.position_index == 0:
|
||||
if param.position_index == 0 \
|
||||
and not function_is_static_method(self._function_value.tree_node):
|
||||
return InstanceExecutedParamName(self._instance, self._function_value, name)
|
||||
return super(AnonymousMethodExecutionFilter, self)._convert_param(param, name)
|
||||
|
||||
|
||||
@@ -295,3 +295,11 @@ def cut_value_at_position(leaf, position):
|
||||
|
||||
def get_string_quote(leaf):
|
||||
return re.match(r'\w*("""|\'{3}|"|\')', leaf.value).group(1)
|
||||
|
||||
|
||||
def function_is_static_method(function_node):
|
||||
for decorator in function_node.get_decorators():
|
||||
dotted_name = decorator.children[1]
|
||||
if dotted_name.get_code() == 'staticmethod':
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -292,6 +292,40 @@ for part in qsplit:
|
||||
#? str()
|
||||
part
|
||||
|
||||
# -----------------
|
||||
# staticmethod, classmethod params
|
||||
# -----------------
|
||||
|
||||
class F():
|
||||
def __init__(self):
|
||||
self.my_variable = 3
|
||||
|
||||
@staticmethod
|
||||
def my_func(param):
|
||||
#? []
|
||||
param.my_
|
||||
#? ['upper']
|
||||
param.uppe
|
||||
#? str()
|
||||
return param
|
||||
|
||||
@staticmethod
|
||||
def my_func_without_call(param):
|
||||
#? []
|
||||
param.my_
|
||||
#? []
|
||||
param.uppe
|
||||
#?
|
||||
return param
|
||||
|
||||
@classmethod
|
||||
def my_method(cls, param):
|
||||
#? []
|
||||
param.my_method
|
||||
|
||||
|
||||
F.my_func('')
|
||||
|
||||
# -----------------
|
||||
# Unknown metaclass
|
||||
# -----------------
|
||||
|
||||
Reference in New Issue
Block a user