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