Fix remaining issue siwh the Param refactoring.

This commit is contained in:
Dave Halter
2015-02-11 01:40:18 +01:00
parent cdbe26786a
commit 6e5ba3de87
4 changed files with 12 additions and 22 deletions

View File

@@ -11,7 +11,7 @@ from jedi._compatibility import builtins as _builtins, unicode
from jedi import debug
from jedi.cache import underscore_memoization, memoize_method
from jedi.evaluate.sys_path import get_sys_path
from jedi.parser.tree import Param, Base
from jedi.parser.tree import Param, Base, Operator, zero_position_modifier
from jedi.evaluate.helpers import FakeName
from . import fake
@@ -85,18 +85,11 @@ class CompiledObject(Base):
params_str, ret = self._parse_function_doc()
tokens = params_str.split(',')
params = []
module = self.get_parent_until()
# it seems like start_pos/end_pos is always (0, 0) for a compiled
# object
start_pos, end_pos = (0, 0), (0, 0)
for p in tokens:
parts = [FakeName(part) for part in p.strip().split('=')]
name = parts[0]
if len(parts) > 2:
default = parts[2]
else:
default = None
params.append(Param(name, module, default))
if len(parts) > 1:
parts.insert(1, Operator(zero_position_modifier, '=', (0, 0)))
params.append(Param(parts, self))
return params
def __repr__(self):

View File

@@ -573,9 +573,6 @@ class FunctionExecution(Executed):
func = base.base_func
self._copy_dict = {func: self, func.parent: func.parent}
helpers.deep_ast_copy(self.base.base_func, self._copy_dict, check_first=True)
# We definitely want the params to be generated. Params are special,
# because they have been altered and are not normal "children".
self.params
@memoize_default(default=())
@recursion.execution_recursion_decorator

View File

@@ -729,7 +729,7 @@ class Function(ClassOrFunc):
"""
Used to store the parsed contents of a python function.
"""
__slots__ = ('listeners', 'params')
__slots__ = ('listeners',)
type = 'funcdef'
def __init__(self, children):
@@ -796,6 +796,10 @@ class Lambda(Function):
lst = self.children[1:-2] # After `def foo`
self.children[1:-2] = _create_params(self, lst)
@property
def params(self):
return self.children[1:-2]
def is_generator(self):
return False
@@ -1138,7 +1142,7 @@ class Param(BaseNode):
@property
def default(self):
try:
return self.children[int(self.children[0] in ('*', '**')) + 1]
return self.children[int(self.children[0] in ('*', '**')) + 2]
except IndexError:
return None
@@ -1162,16 +1166,12 @@ class Param(BaseNode):
@property
def position_nr(self):
return self.parent.params.index(self)
return self.parent.children.index(self) - 1
@property
def parent_function(self):
return self.get_parent_until(IsScope)
def get_code(self):
df = '' if self.default is None else '=' + self.default.get_code()
return self._tfpdef().get_code() + df
def __repr__(self):
default = '' if self.default is None else '=%s' % self.default
return '<%s: %s>' % (type(self).__name__, str(self._tfpdef()) + default)

View File

@@ -166,7 +166,7 @@ class TestCallSignatures(TestCase):
signatures = Script(s).call_signatures()
assert len(signatures) == 1
x = [p.description for p in signatures[0].params]
assert x == ['args']
assert x == ['*args']
def test_additional_brackets(self):
self._run('str((', 'str', 0)