forked from VimPlug/jedi
Fix issue with lambda parsing; new test cases now pass.
This commit is contained in:
+31
-3
@@ -748,6 +748,15 @@ def _create_params(parent, argslist_list):
|
|||||||
class Function(ClassOrFunc):
|
class Function(ClassOrFunc):
|
||||||
"""
|
"""
|
||||||
Used to store the parsed contents of a python function.
|
Used to store the parsed contents of a python function.
|
||||||
|
|
||||||
|
Children:
|
||||||
|
0) <Keyword: def>
|
||||||
|
1) <Name>
|
||||||
|
2) parameter list (including open-paren and close-paren <Operator>s)
|
||||||
|
3) <Operator: :>
|
||||||
|
4) Node() representing function body
|
||||||
|
5) ??
|
||||||
|
6) annotation (if present)
|
||||||
"""
|
"""
|
||||||
__slots__ = ('listeners',)
|
__slots__ = ('listeners',)
|
||||||
type = 'funcdef'
|
type = 'funcdef'
|
||||||
@@ -760,6 +769,7 @@ class Function(ClassOrFunc):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def params(self):
|
def params(self):
|
||||||
|
# Contents of parameter lit minus the leading <Operator: (> and the trailing <Operator: )>.
|
||||||
return self.children[2].children[1:-1]
|
return self.children[2].children[1:-1]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -791,10 +801,13 @@ class Function(ClassOrFunc):
|
|||||||
|
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
func_name = func_name or self.children[1]
|
func_name = func_name or self.name
|
||||||
code = unicode(func_name) + self.children[2].get_code()
|
code = unicode(func_name) + self._get_paramlist_code()
|
||||||
return '\n'.join(textwrap.wrap(code, width))
|
return '\n'.join(textwrap.wrap(code, width))
|
||||||
|
|
||||||
|
def _get_paramlist_code(self):
|
||||||
|
return self.children[2].get_code()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def doc(self):
|
def doc(self):
|
||||||
""" Return a document string including call signature. """
|
""" Return a document string including call signature. """
|
||||||
@@ -805,6 +818,12 @@ class Function(ClassOrFunc):
|
|||||||
class Lambda(Function):
|
class Lambda(Function):
|
||||||
"""
|
"""
|
||||||
Lambdas are basically trimmed functions, so give it the same interface.
|
Lambdas are basically trimmed functions, so give it the same interface.
|
||||||
|
|
||||||
|
Children:
|
||||||
|
0) <Keyword: lambda>
|
||||||
|
*) <Param x> for each argument x
|
||||||
|
-2) <Operator: :>
|
||||||
|
-1) Node() representing body
|
||||||
"""
|
"""
|
||||||
type = 'lambda'
|
type = 'lambda'
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
@@ -813,9 +832,17 @@ class Lambda(Function):
|
|||||||
# We don't want to call the Function constructor, call its parent.
|
# We don't want to call the Function constructor, call its parent.
|
||||||
super(Function, self).__init__(children)
|
super(Function, self).__init__(children)
|
||||||
self.listeners = set() # not used here, but in evaluation.
|
self.listeners = set() # not used here, but in evaluation.
|
||||||
lst = self.children[1:-2] # After `def foo`
|
lst = self.children[1:-2] # Everything between `lambda` and the `:` operator is a parameter.
|
||||||
self.children[1:-2] = _create_params(self, lst)
|
self.children[1:-2] = _create_params(self, lst)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
# Borrow the position of the <Keyword: lambda> AST node.
|
||||||
|
return Name(self.children[0].position_modifier, '<lambda>', self.children[0].start_pos)
|
||||||
|
|
||||||
|
def _get_paramlist_code(self):
|
||||||
|
return '(' + ''.join(param.get_code() for param in self.params).strip() + ')'
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def params(self):
|
def params(self):
|
||||||
return self.children[1:-2]
|
return self.children[1:-2]
|
||||||
@@ -823,6 +850,7 @@ class Lambda(Function):
|
|||||||
def is_generator(self):
|
def is_generator(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
def yields(self):
|
def yields(self):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user