1
0
forked from VimPlug/jedi

Merge dev into linter.

This commit is contained in:
Dave Halter
2015-11-10 21:49:32 +01:00
32 changed files with 451 additions and 123 deletions

View File

@@ -825,6 +825,15 @@ def _create_params(parent, argslist_list):
class Function(ClassOrFunc):
"""
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',)
type = 'funcdef'
@@ -837,6 +846,7 @@ class Function(ClassOrFunc):
@property
def params(self):
# Contents of parameter lit minus the leading <Operator: (> and the trailing <Operator: )>.
return self.children[2].children[1:-1]
@property
@@ -868,10 +878,13 @@ class Function(ClassOrFunc):
:rtype: str
"""
func_name = func_name or self.children[1]
code = unicode(func_name) + self.children[2].get_code()
func_name = func_name or self.name
code = unicode(func_name) + self._get_paramlist_code()
return '\n'.join(textwrap.wrap(code, width))
def _get_paramlist_code(self):
return self.children[2].get_code()
@property
def doc(self):
""" Return a document string including call signature. """
@@ -897,6 +910,12 @@ class Function(ClassOrFunc):
class Lambda(Function):
"""
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'
__slots__ = ()
@@ -905,9 +924,17 @@ class Lambda(Function):
# We don't want to call the Function constructor, call its parent.
super(Function, self).__init__(children)
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)
@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
def params(self):
return self.children[1:-2]
@@ -915,6 +942,7 @@ class Lambda(Function):
def is_generator(self):
return False
@property
def yields(self):
return []