mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 14:04:26 +08:00
Add at least partial support for signatures for builtins
This commit is contained in:
@@ -14,6 +14,7 @@ from jedi.evaluate.lazy_context import LazyKnownContext
|
||||
from jedi.evaluate.compiled.access import _sentinel
|
||||
from jedi.evaluate.cache import evaluator_function_cache
|
||||
from jedi.evaluate.helpers import reraise_getitem_errors, execute_evaluated
|
||||
from jedi.evaluate.signature import BuiltinSignature
|
||||
|
||||
|
||||
class CheckAttribute(object):
|
||||
@@ -116,6 +117,9 @@ class CompiledObject(Context):
|
||||
for signature_param in signature_params:
|
||||
yield SignatureParamName(self, signature_param)
|
||||
|
||||
def get_signatures(self):
|
||||
return [BuiltinSignature(self)]
|
||||
|
||||
def __repr__(self):
|
||||
return '<%s: %s>' % (self.__class__.__name__, self.access_handle.get_repr())
|
||||
|
||||
|
||||
61
jedi/evaluate/signature.py
Normal file
61
jedi/evaluate/signature.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from abc import abstractproperty
|
||||
|
||||
|
||||
class AbstractSignature(object):
|
||||
def __init__(self, is_bound=False):
|
||||
self.is_bound = is_bound
|
||||
|
||||
@abstractproperty
|
||||
def name(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def annotation(self):
|
||||
return None
|
||||
|
||||
def to_string(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def bind(self):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_param_names(self):
|
||||
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
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
name = self.function_context.name
|
||||
if name.string_name == '__init__':
|
||||
try:
|
||||
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 annotation(self):
|
||||
return self.function_context.tree_node.annotation
|
||||
|
||||
def to_string(self, normalize=False):
|
||||
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
|
||||
|
||||
def bind(self):
|
||||
raise NotImplementedError('pls implement, need test case')
|
||||
Reference in New Issue
Block a user