mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Start implementing get_signatures
This commit is contained in:
@@ -345,11 +345,12 @@ class Script(object):
|
|||||||
)
|
)
|
||||||
debug.speed('func_call followed')
|
debug.speed('func_call followed')
|
||||||
|
|
||||||
return [classes.CallSignature(self._evaluator, d.name,
|
return [classes.CallSignature(self._evaluator, 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)
|
||||||
for d in definitions if hasattr(d, 'py__call__')]
|
for d in definitions
|
||||||
|
for signature in d.get_signatures()]
|
||||||
|
|
||||||
def _analysis(self):
|
def _analysis(self):
|
||||||
self._evaluator.is_analysis = True
|
self._evaluator.is_analysis = True
|
||||||
|
|||||||
@@ -600,11 +600,12 @@ class CallSignature(Definition):
|
|||||||
It knows what functions you are currently in. e.g. `isinstance(` would
|
It knows what functions you are currently in. e.g. `isinstance(` would
|
||||||
return the `isinstance` function. without `(` it would return nothing.
|
return the `isinstance` function. without `(` it would return nothing.
|
||||||
"""
|
"""
|
||||||
def __init__(self, evaluator, executable_name, bracket_start_pos, index, key_name_str):
|
def __init__(self, evaluator, signature, bracket_start_pos, index, key_name_str):
|
||||||
super(CallSignature, self).__init__(evaluator, executable_name)
|
super(CallSignature, self).__init__(evaluator, signature.name)
|
||||||
self._index = index
|
self._index = index
|
||||||
self._key_name_str = key_name_str
|
self._key_name_str = key_name_str
|
||||||
self._bracket_start_pos = bracket_start_pos
|
self._bracket_start_pos = bracket_start_pos
|
||||||
|
self._signature = signature
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def index(self):
|
def index(self):
|
||||||
|
|||||||
@@ -131,6 +131,9 @@ class Context(HelperContextMixin, BaseContext):
|
|||||||
)
|
)
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
return []
|
||||||
|
|
||||||
def is_class(self):
|
def is_class(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from jedi.evaluate import docstrings
|
|||||||
from jedi.evaluate import pep0484
|
from jedi.evaluate import pep0484
|
||||||
from jedi.evaluate import flow_analysis
|
from jedi.evaluate import flow_analysis
|
||||||
from jedi.evaluate import helpers
|
from jedi.evaluate import helpers
|
||||||
|
from jedi.evaluate.signature import TreeSignature
|
||||||
from jedi.evaluate.arguments import AnonymousArguments
|
from jedi.evaluate.arguments import AnonymousArguments
|
||||||
from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter, \
|
from jedi.evaluate.filters import ParserTreeFilter, FunctionExecutionFilter, \
|
||||||
ContextName, AbstractNameDefinition, ParamName
|
ContextName, AbstractNameDefinition, ParamName
|
||||||
@@ -135,6 +136,9 @@ class FunctionContext(use_metaclass(CachedMetaClass, FunctionMixin, TreeContext)
|
|||||||
def get_matching_functions(self, arguments):
|
def get_matching_functions(self, arguments):
|
||||||
yield self
|
yield self
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
return [TreeSignature(self)]
|
||||||
|
|
||||||
|
|
||||||
class MethodContext(FunctionContext):
|
class MethodContext(FunctionContext):
|
||||||
def __init__(self, evaluator, class_context, *args, **kwargs):
|
def __init__(self, evaluator, class_context, *args, **kwargs):
|
||||||
@@ -365,6 +369,9 @@ class OverloadedFunctionContext(FunctionMixin, ContextWrapper):
|
|||||||
debug.dbg("Overloading no match: %s@%s (%s)",
|
debug.dbg("Overloading no match: %s@%s (%s)",
|
||||||
signature, f.tree_node.start_pos[0], arguments, color='BLUE')
|
signature, f.tree_node.start_pos[0], arguments, color='BLUE')
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
return [TreeSignature(f) for f in self.overloaded_functions]
|
||||||
|
|
||||||
|
|
||||||
def signature_matches(function_context, arguments):
|
def signature_matches(function_context, arguments):
|
||||||
unpacked_arguments = arguments.unpack()
|
unpacked_arguments = arguments.unpack()
|
||||||
|
|||||||
@@ -420,6 +420,9 @@ class BoundMethod(FunctionMixin, ContextWrapper):
|
|||||||
else:
|
else:
|
||||||
yield BoundMethod(self.instance, self.class_context, func)
|
yield BoundMethod(self.instance, self.class_context, func)
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
return [sig.bind() 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)
|
||||||
|
|
||||||
|
|||||||
@@ -301,3 +301,9 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
|
|||||||
given_types=tuple(remap_type_vars())
|
given_types=tuple(remap_type_vars())
|
||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def get_signatures(self):
|
||||||
|
init_funcs = self.py__getattribute__('__init__')
|
||||||
|
return [
|
||||||
|
s for f in init_funcs for s in f.get_signatures()
|
||||||
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user