mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
signature is now a subclass of definitions
This commit is contained in:
@@ -137,7 +137,7 @@ class Script(object):
|
|||||||
# add named params
|
# add named params
|
||||||
for call_sig in self.call_signatures():
|
for call_sig in self.call_signatures():
|
||||||
# allow protected access, because it's a public API.
|
# allow protected access, because it's a public API.
|
||||||
module = call_sig._executable.get_parent_until()
|
module = call_sig._definition.get_parent_until()
|
||||||
# Compiled modules typically don't allow keyword arguments.
|
# Compiled modules typically don't allow keyword arguments.
|
||||||
if not isinstance(module, compiled.CompiledObject):
|
if not isinstance(module, compiled.CompiledObject):
|
||||||
for p in call_sig.params:
|
for p in call_sig.params:
|
||||||
|
|||||||
+12
-12
@@ -541,30 +541,30 @@ class Definition(BaseDefinition):
|
|||||||
return defined_names(self._evaluator, d)
|
return defined_names(self._evaluator, d)
|
||||||
|
|
||||||
|
|
||||||
class CallSignature(object):
|
class CallSignature(Definition):
|
||||||
"""
|
"""
|
||||||
`CallSignature` objects is the return value of `Script.function_definition`.
|
`CallSignature` objects is the return value of `Script.function_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, call, index):
|
def __init__(self, evaluator, executable, call, index):
|
||||||
self._evaluator = evaluator
|
super(CallSignature, self).__init__(evaluator, executable)
|
||||||
self._executable = executable
|
|
||||||
self.index = index
|
self.index = index
|
||||||
|
""" The param index of the current call. """
|
||||||
self._call = call
|
self._call = call
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def params(self):
|
def params(self):
|
||||||
if self._executable.isinstance(er.Function):
|
if self._definition.isinstance(er.Function):
|
||||||
if isinstance(self._executable, er.InstanceElement):
|
if isinstance(self._definition, er.InstanceElement):
|
||||||
params = self._executable.params[1:]
|
params = self._definition.params[1:]
|
||||||
else:
|
else:
|
||||||
params = self._executable.params
|
params = self._definition.params
|
||||||
elif self._executable.isinstance(er.compiled.CompiledObject):
|
elif self._definition.isinstance(er.compiled.CompiledObject):
|
||||||
params = self._executable.params
|
params = self._definition.params
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
sub = self._executable.get_subscope_by_name('__init__')
|
sub = self._definition.get_subscope_by_name('__init__')
|
||||||
params = sub.params[1:] # ignore self
|
params = sub.params[1:] # ignore self
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return []
|
return []
|
||||||
@@ -584,10 +584,10 @@ class CallSignature(object):
|
|||||||
@property
|
@property
|
||||||
def call_name(self):
|
def call_name(self):
|
||||||
""" The name (e.g. 'isinstance') as a string. """
|
""" The name (e.g. 'isinstance') as a string. """
|
||||||
return unicode(self._executable.name)
|
return unicode(self._definition.name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s index %s>' % (type(self).__name__, self._executable,
|
return '<%s: %s index %s>' % (type(self).__name__, self._definition,
|
||||||
self.index)
|
self.index)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ class TestParams(TestCase):
|
|||||||
assert p[1].name == 'mode'
|
assert p[1].name == 'mode'
|
||||||
|
|
||||||
|
|
||||||
def test_signature_is_definition(TestCase):
|
def test_signature_is_definition():
|
||||||
"""
|
"""
|
||||||
Through inheritance, a call signature is a sub class of Definition.
|
Through inheritance, a call signature is a sub class of Definition.
|
||||||
Check if the attributes match.
|
Check if the attributes match.
|
||||||
@@ -193,9 +193,11 @@ def test_signature_is_definition(TestCase):
|
|||||||
|
|
||||||
# Now compare all the attributes that a CallSignature must also have.
|
# Now compare all the attributes that a CallSignature must also have.
|
||||||
for attr_name in dir(definition):
|
for attr_name in dir(definition):
|
||||||
|
if attr_name.startswith('_') or attr_name == 'defined_names':
|
||||||
|
continue
|
||||||
attribute = getattr(definition, attr_name)
|
attribute = getattr(definition, attr_name)
|
||||||
signature_attribute = getattr(signature, attr_name)
|
signature_attribute = getattr(signature, attr_name)
|
||||||
if inspect.isfunction(attribute):
|
if inspect.ismethod(attribute):
|
||||||
assert attribute() == signature_attribute()
|
assert attribute() == signature_attribute()
|
||||||
else:
|
else:
|
||||||
assert attribute == signature_attribute
|
assert attribute == signature_attribute
|
||||||
|
|||||||
Reference in New Issue
Block a user