mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 05:54:25 +08:00
Change signature a little bit
This commit is contained in:
@@ -345,7 +345,7 @@ class Script(object):
|
||||
)
|
||||
debug.speed('func_call followed')
|
||||
|
||||
return [classes.CallSignature(definition, signature,
|
||||
return [classes.CallSignature(signature._context, signature,
|
||||
call_signature_details.bracket_leaf.start_pos,
|
||||
call_signature_details.call_index,
|
||||
call_signature_details.keyword_name_str)
|
||||
|
||||
@@ -220,7 +220,7 @@ class AbstractInstanceContext(Context):
|
||||
|
||||
def get_signatures(self):
|
||||
init_funcs = self.py__getattribute__('__call__')
|
||||
return [sig.bind() for sig in init_funcs.get_signatures()]
|
||||
return [sig.bind(self) for sig in init_funcs.get_signatures()]
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s of %s(%s)>" % (self.__class__.__name__, self.class_context,
|
||||
@@ -427,7 +427,7 @@ class BoundMethod(FunctionMixin, ContextWrapper):
|
||||
yield BoundMethod(self.instance, self.class_context, func)
|
||||
|
||||
def get_signatures(self):
|
||||
return [sig.bind() for sig in self._wrapped_context.get_signatures()]
|
||||
return [sig.bind(self) for sig in self._wrapped_context.get_signatures()]
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self._wrapped_context)
|
||||
|
||||
@@ -292,4 +292,4 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
|
||||
|
||||
def get_signatures(self):
|
||||
init_funcs = self.py__getattribute__('__init__')
|
||||
return [sig.bind() for sig in init_funcs.get_signatures()]
|
||||
return [sig.bind(self) for sig in init_funcs.get_signatures()]
|
||||
|
||||
@@ -2,7 +2,8 @@ from abc import abstractproperty
|
||||
|
||||
|
||||
class AbstractSignature(object):
|
||||
def __init__(self, is_bound=False):
|
||||
def __init__(self, context, is_bound=False):
|
||||
self._context = context
|
||||
self.is_bound = is_bound
|
||||
|
||||
@abstractproperty
|
||||
@@ -19,43 +20,43 @@ class AbstractSignature(object):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_param_names(self):
|
||||
param_names = self.function_context.get_param_names()
|
||||
param_names = self._function_context.get_param_names()
|
||||
if self.is_bound:
|
||||
return param_names[1:]
|
||||
return param_names
|
||||
|
||||
|
||||
class TreeSignature(AbstractSignature):
|
||||
def __init__(self, function_context, is_bound=False):
|
||||
super(TreeSignature, self).__init__(is_bound)
|
||||
self.function_context = function_context
|
||||
def __init__(self, context, function_context=None, is_bound=False):
|
||||
super(TreeSignature, self).__init__(context, is_bound)
|
||||
self._function_context = function_context or context
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
name = self.function_context.name
|
||||
name = self._function_context.name
|
||||
if name.string_name == '__init__':
|
||||
try:
|
||||
class_context = self.function_context.class_context
|
||||
class_context = self._function_context.class_context
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
return class_context.name
|
||||
return name
|
||||
|
||||
def bind(self):
|
||||
return TreeSignature(self.function_context, is_bound=True)
|
||||
def bind(self, context):
|
||||
return TreeSignature(context, self._function_context, is_bound=True)
|
||||
|
||||
def annotation(self):
|
||||
return self.function_context.tree_node.annotation
|
||||
return self._function_context.tree_node.annotation
|
||||
|
||||
def to_string(self, normalize=False):
|
||||
return self.function_context.tree_node
|
||||
return self._function_context.tree_node
|
||||
|
||||
|
||||
class BuiltinSignature(AbstractSignature):
|
||||
def __init__(self, compiled_obj, is_bound=False):
|
||||
super(BuiltinSignature, self).__init__(is_bound=is_bound)
|
||||
self.function_context = compiled_obj
|
||||
@property
|
||||
def _function_context(self):
|
||||
return self._context
|
||||
|
||||
def bind(self):
|
||||
raise NotImplementedError('pls implement, need test case')
|
||||
|
||||
Reference in New Issue
Block a user