forked from VimPlug/jedi
Make sure py__get__ is defined on all values
Also define matches_signature on all signatures, there's definitely cases where that might be called
This commit is contained in:
@@ -239,6 +239,10 @@ class Value(HelperValueMixin, BaseValue):
|
|||||||
"""
|
"""
|
||||||
return NO_VALUES
|
return NO_VALUES
|
||||||
|
|
||||||
|
def py__get__(self, instance, class_value):
|
||||||
|
debug.warning("No __get__ defined on %s", self)
|
||||||
|
return ValueSet([self])
|
||||||
|
|
||||||
def get_qualified_names(self):
|
def get_qualified_names(self):
|
||||||
# Returns Optional[Tuple[str, ...]]
|
# Returns Optional[Tuple[str, ...]]
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -56,6 +56,9 @@ class AbstractSignature(_SignatureMixin):
|
|||||||
def bind(self, value):
|
def bind(self, value):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def matches_signature(self, arguments):
|
||||||
|
return True
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.value is self._function_value:
|
if self.value is self._function_value:
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self.value)
|
return '<%s: %s>' % (self.__class__.__name__, self.value)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from jedi.inference.arguments import ValuesArguments, TreeArgumentsWrapper
|
|||||||
from jedi.inference.value.function import \
|
from jedi.inference.value.function import \
|
||||||
FunctionValue, FunctionMixin, OverloadedFunctionValue, \
|
FunctionValue, FunctionMixin, OverloadedFunctionValue, \
|
||||||
BaseFunctionExecutionContext, FunctionExecutionContext
|
BaseFunctionExecutionContext, FunctionExecutionContext
|
||||||
from jedi.inference.value.klass import apply_py__get__, ClassFilter
|
from jedi.inference.value.klass import ClassFilter
|
||||||
from jedi.inference.value.dynamic_arrays import get_dynamic_array_instance
|
from jedi.inference.value.dynamic_arrays import get_dynamic_array_instance
|
||||||
|
|
||||||
|
|
||||||
@@ -263,7 +263,7 @@ class _BaseTreeInstance(AbstractInstanceValue):
|
|||||||
|
|
||||||
return ValueSet.from_sets(name.infer().execute(arguments) for name in names)
|
return ValueSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||||
|
|
||||||
def py__get__(self, obj, class_value):
|
def py__get__(self, instance, class_value):
|
||||||
"""
|
"""
|
||||||
obj may be None.
|
obj may be None.
|
||||||
"""
|
"""
|
||||||
@@ -271,9 +271,9 @@ class _BaseTreeInstance(AbstractInstanceValue):
|
|||||||
# `method` is the new parent of the array, don't know if that's good.
|
# `method` is the new parent of the array, don't know if that's good.
|
||||||
names = self.get_function_slot_names(u'__get__')
|
names = self.get_function_slot_names(u'__get__')
|
||||||
if names:
|
if names:
|
||||||
if obj is None:
|
if instance is None:
|
||||||
obj = compiled.builtin_from_name(self.inference_state, u'None')
|
instance = compiled.builtin_from_name(self.inference_state, u'None')
|
||||||
return self.execute_function_slots(names, obj, class_value)
|
return self.execute_function_slots(names, instance, class_value)
|
||||||
else:
|
else:
|
||||||
return ValueSet([self])
|
return ValueSet([self])
|
||||||
|
|
||||||
@@ -320,7 +320,8 @@ class TreeInstance(_BaseTreeInstance):
|
|||||||
for signature in self.class_value.py__getattribute__('__init__').get_signatures():
|
for signature in self.class_value.py__getattribute__('__init__').get_signatures():
|
||||||
# Just take the first result, it should always be one, because we
|
# Just take the first result, it should always be one, because we
|
||||||
# control the typeshed code.
|
# control the typeshed code.
|
||||||
if not signature.matches_signature(args):
|
if not signature.matches_signature(args) \
|
||||||
|
or signature.value.tree_node is None:
|
||||||
# First check if the signature even matches, if not we don't
|
# First check if the signature even matches, if not we don't
|
||||||
# need to infer anything.
|
# need to infer anything.
|
||||||
continue
|
continue
|
||||||
@@ -481,7 +482,7 @@ class LazyInstanceClassName(object):
|
|||||||
@iterator_to_value_set
|
@iterator_to_value_set
|
||||||
def infer(self):
|
def infer(self):
|
||||||
for result_value in self._class_member_name.infer():
|
for result_value in self._class_member_name.infer():
|
||||||
for c in apply_py__get__(result_value, self._instance, self._instance.py__class__()):
|
for c in result_value.py__get__(self._instance, self._instance.py__class__()):
|
||||||
yield c
|
yield c
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
|||||||
@@ -53,16 +53,6 @@ from jedi.inference.value.function import FunctionAndClassBase
|
|||||||
from jedi.plugins import plugin_manager
|
from jedi.plugins import plugin_manager
|
||||||
|
|
||||||
|
|
||||||
def apply_py__get__(value, instance, class_value):
|
|
||||||
try:
|
|
||||||
method = value.py__get__
|
|
||||||
except AttributeError:
|
|
||||||
yield value
|
|
||||||
else:
|
|
||||||
for descriptor_value in method(instance, class_value):
|
|
||||||
yield descriptor_value
|
|
||||||
|
|
||||||
|
|
||||||
class ClassName(TreeNameDefinition):
|
class ClassName(TreeNameDefinition):
|
||||||
def __init__(self, class_value, tree_name, name_context, apply_decorators):
|
def __init__(self, class_value, tree_name, name_context, apply_decorators):
|
||||||
super(ClassName, self).__init__(class_value.as_context(), tree_name)
|
super(ClassName, self).__init__(class_value.as_context(), tree_name)
|
||||||
@@ -79,9 +69,7 @@ class ClassName(TreeNameDefinition):
|
|||||||
|
|
||||||
for result_value in inferred:
|
for result_value in inferred:
|
||||||
if self._apply_decorators:
|
if self._apply_decorators:
|
||||||
for c in apply_py__get__(result_value,
|
for c in result_value.py__get__(instance=None, class_value=self._class_value):
|
||||||
instance=None,
|
|
||||||
class_value=self._class_value):
|
|
||||||
yield c
|
yield c
|
||||||
else:
|
else:
|
||||||
yield result_value
|
yield result_value
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ def builtins_isinstance(objects, types, arguments, inference_state):
|
|||||||
|
|
||||||
|
|
||||||
class StaticMethodObject(ValueWrapper):
|
class StaticMethodObject(ValueWrapper):
|
||||||
def py__get__(self, instance, klass):
|
def py__get__(self, instance, class_value):
|
||||||
return ValueSet([self._wrapped_value])
|
return ValueSet([self._wrapped_value])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user