mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Fix remaining issue siwh the Param refactoring.
This commit is contained in:
@@ -11,7 +11,7 @@ from jedi._compatibility import builtins as _builtins, unicode
|
|||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.cache import underscore_memoization, memoize_method
|
from jedi.cache import underscore_memoization, memoize_method
|
||||||
from jedi.evaluate.sys_path import get_sys_path
|
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 jedi.evaluate.helpers import FakeName
|
||||||
from . import fake
|
from . import fake
|
||||||
|
|
||||||
@@ -85,18 +85,11 @@ class CompiledObject(Base):
|
|||||||
params_str, ret = self._parse_function_doc()
|
params_str, ret = self._parse_function_doc()
|
||||||
tokens = params_str.split(',')
|
tokens = params_str.split(',')
|
||||||
params = []
|
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:
|
for p in tokens:
|
||||||
parts = [FakeName(part) for part in p.strip().split('=')]
|
parts = [FakeName(part) for part in p.strip().split('=')]
|
||||||
name = parts[0]
|
if len(parts) > 1:
|
||||||
if len(parts) > 2:
|
parts.insert(1, Operator(zero_position_modifier, '=', (0, 0)))
|
||||||
default = parts[2]
|
params.append(Param(parts, self))
|
||||||
else:
|
|
||||||
default = None
|
|
||||||
params.append(Param(name, module, default))
|
|
||||||
return params
|
return params
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -573,9 +573,6 @@ class FunctionExecution(Executed):
|
|||||||
func = base.base_func
|
func = base.base_func
|
||||||
self._copy_dict = {func: self, func.parent: func.parent}
|
self._copy_dict = {func: self, func.parent: func.parent}
|
||||||
helpers.deep_ast_copy(self.base.base_func, self._copy_dict, check_first=True)
|
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=())
|
@memoize_default(default=())
|
||||||
@recursion.execution_recursion_decorator
|
@recursion.execution_recursion_decorator
|
||||||
|
|||||||
@@ -729,7 +729,7 @@ class Function(ClassOrFunc):
|
|||||||
"""
|
"""
|
||||||
Used to store the parsed contents of a python function.
|
Used to store the parsed contents of a python function.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('listeners', 'params')
|
__slots__ = ('listeners',)
|
||||||
type = 'funcdef'
|
type = 'funcdef'
|
||||||
|
|
||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
@@ -796,6 +796,10 @@ class Lambda(Function):
|
|||||||
lst = self.children[1:-2] # After `def foo`
|
lst = self.children[1:-2] # After `def foo`
|
||||||
self.children[1:-2] = _create_params(self, lst)
|
self.children[1:-2] = _create_params(self, lst)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def params(self):
|
||||||
|
return self.children[1:-2]
|
||||||
|
|
||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -1138,7 +1142,7 @@ class Param(BaseNode):
|
|||||||
@property
|
@property
|
||||||
def default(self):
|
def default(self):
|
||||||
try:
|
try:
|
||||||
return self.children[int(self.children[0] in ('*', '**')) + 1]
|
return self.children[int(self.children[0] in ('*', '**')) + 2]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -1162,16 +1166,12 @@ class Param(BaseNode):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def position_nr(self):
|
def position_nr(self):
|
||||||
return self.parent.params.index(self)
|
return self.parent.children.index(self) - 1
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent_function(self):
|
def parent_function(self):
|
||||||
return self.get_parent_until(IsScope)
|
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):
|
def __repr__(self):
|
||||||
default = '' if self.default is None else '=%s' % self.default
|
default = '' if self.default is None else '=%s' % self.default
|
||||||
return '<%s: %s>' % (type(self).__name__, str(self._tfpdef()) + default)
|
return '<%s: %s>' % (type(self).__name__, str(self._tfpdef()) + default)
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ class TestCallSignatures(TestCase):
|
|||||||
signatures = Script(s).call_signatures()
|
signatures = Script(s).call_signatures()
|
||||||
assert len(signatures) == 1
|
assert len(signatures) == 1
|
||||||
x = [p.description for p in signatures[0].params]
|
x = [p.description for p in signatures[0].params]
|
||||||
assert x == ['args']
|
assert x == ['*args']
|
||||||
|
|
||||||
def test_additional_brackets(self):
|
def test_additional_brackets(self):
|
||||||
self._run('str((', 'str', 0)
|
self._run('str((', 'str', 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user