forked from VimPlug/jedi
Fix the last remaining issues with function signature
This commit is contained in:
@@ -101,7 +101,7 @@ class FunctionMixin(object):
|
|||||||
return FunctionExecutionContext(self.evaluator, self.parent_context, self, arguments)
|
return FunctionExecutionContext(self.evaluator, self.parent_context, self, arguments)
|
||||||
|
|
||||||
def get_signatures(self):
|
def get_signatures(self):
|
||||||
return [TreeSignature(self)]
|
return [TreeSignature(f) for f in self.get_signature_functions()]
|
||||||
|
|
||||||
|
|
||||||
class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndClassBase)):
|
class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndClassBase)):
|
||||||
@@ -150,6 +150,9 @@ class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, FunctionAndC
|
|||||||
def get_default_param_context(self):
|
def get_default_param_context(self):
|
||||||
return self.parent_context
|
return self.parent_context
|
||||||
|
|
||||||
|
def get_signature_functions(self):
|
||||||
|
return [self]
|
||||||
|
|
||||||
|
|
||||||
class MethodContext(FunctionContext):
|
class MethodContext(FunctionContext):
|
||||||
def __init__(self, evaluator, class_context, *args, **kwargs):
|
def __init__(self, evaluator, class_context, *args, **kwargs):
|
||||||
@@ -393,8 +396,8 @@ class OverloadedFunctionContext(FunctionMixin, ContextWrapper):
|
|||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
return ContextSet.from_sets(fe.infer() for fe in function_executions)
|
return ContextSet.from_sets(fe.infer() for fe in function_executions)
|
||||||
|
|
||||||
def get_signatures(self):
|
def get_signature_functions(self):
|
||||||
return [s for f in self._overloaded_functions for s in f.get_signatures()]
|
return self._overloaded_functions
|
||||||
|
|
||||||
|
|
||||||
def _find_overload_functions(context, tree_node):
|
def _find_overload_functions(context, tree_node):
|
||||||
|
|||||||
@@ -399,8 +399,14 @@ class BoundMethod(FunctionMixin, ContextWrapper):
|
|||||||
function_execution = self.get_function_execution(arguments)
|
function_execution = self.get_function_execution(arguments)
|
||||||
return function_execution.infer()
|
return function_execution.infer()
|
||||||
|
|
||||||
|
def get_signature_functions(self):
|
||||||
|
return [
|
||||||
|
BoundMethod(self.instance, f)
|
||||||
|
for f in self._wrapped_context.get_signature_functions()
|
||||||
|
]
|
||||||
|
|
||||||
def get_signatures(self):
|
def get_signatures(self):
|
||||||
return [sig.bind(self, self) for sig in self._wrapped_context.get_signatures()]
|
return [sig.bind(self) for sig in super(BoundMethod, self).get_signatures()]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self._wrapped_context)
|
return '<%s: %s>' % (self.__class__.__name__, self._wrapped_context)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class AbstractSignature(_SignatureMixin):
|
|||||||
return param_names[1:]
|
return param_names[1:]
|
||||||
return param_names
|
return param_names
|
||||||
|
|
||||||
def bind(self, context, function_context=None):
|
def bind(self, context):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
@@ -62,8 +62,8 @@ class TreeSignature(AbstractSignature):
|
|||||||
super(TreeSignature, self).__init__(context, is_bound)
|
super(TreeSignature, self).__init__(context, is_bound)
|
||||||
self._function_context = function_context or context
|
self._function_context = function_context or context
|
||||||
|
|
||||||
def bind(self, context, function_context=None):
|
def bind(self, context):
|
||||||
return TreeSignature(context, function_context or self._function_context, is_bound=True)
|
return TreeSignature(context, self._function_context, is_bound=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _annotation(self):
|
def _annotation(self):
|
||||||
@@ -101,7 +101,7 @@ class BuiltinSignature(AbstractSignature):
|
|||||||
def _function_context(self):
|
def _function_context(self):
|
||||||
return self.context
|
return self.context
|
||||||
|
|
||||||
def bind(self, context, function_context=None):
|
def bind(self, context):
|
||||||
assert not self.is_bound
|
assert not self.is_bound
|
||||||
return BuiltinSignature(context, self._return_string, is_bound=True)
|
return BuiltinSignature(context, self._return_string, is_bound=True)
|
||||||
|
|
||||||
|
|||||||
@@ -666,6 +666,9 @@ class Wrapped(ContextWrapper, FunctionMixin):
|
|||||||
def name(self):
|
def name(self):
|
||||||
return self._original_function.name
|
return self._original_function.name
|
||||||
|
|
||||||
|
def get_signature_functions(self):
|
||||||
|
return [self]
|
||||||
|
|
||||||
|
|
||||||
class ReplacedNameSignature(SignatureWrapper):
|
class ReplacedNameSignature(SignatureWrapper):
|
||||||
def __init__(self, signature, name):
|
def __init__(self, signature, name):
|
||||||
|
|||||||
Reference in New Issue
Block a user