mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-15 01:57:06 +08:00
Removed the name attribute from lambda. It doesn't exist so don't fake it.
This commit is contained in:
@@ -192,6 +192,9 @@ def follow_param(module_context, param):
|
|||||||
for p in _evaluate_for_statement_string(module_context, param_str)]
|
for p in _evaluate_for_statement_string(module_context, param_str)]
|
||||||
)
|
)
|
||||||
func = param.get_parent_function()
|
func = param.get_parent_function()
|
||||||
|
if func.type == 'lambda':
|
||||||
|
return set()
|
||||||
|
|
||||||
types = eval_docstring(func.raw_doc)
|
types = eval_docstring(func.raw_doc)
|
||||||
if func.name.value == '__init__':
|
if func.name.value == '__init__':
|
||||||
cls = search_ancestor(func, 'classdef')
|
cls = search_ancestor(func, 'classdef')
|
||||||
|
|||||||
@@ -221,6 +221,20 @@ class ClassContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
|||||||
return ContextName(self, self.tree_node.name)
|
return ContextName(self, self.tree_node.name)
|
||||||
|
|
||||||
|
|
||||||
|
class LambdaName(AbstractNameDefinition):
|
||||||
|
string_name = '<lambda>'
|
||||||
|
|
||||||
|
def __init__(self, lambda_context):
|
||||||
|
self._lambda_context = lambda_context
|
||||||
|
self.parent_context = lambda_context.parent_context
|
||||||
|
|
||||||
|
def start_pos(self):
|
||||||
|
return self._lambda_context.tree_node.start_pos
|
||||||
|
|
||||||
|
def infer(self):
|
||||||
|
return set([self._lambda_context])
|
||||||
|
|
||||||
|
|
||||||
class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
||||||
"""
|
"""
|
||||||
Needed because of decorators. Decorators are evaluated here.
|
Needed because of decorators. Decorators are evaluated here.
|
||||||
@@ -276,6 +290,8 @@ class FunctionContext(use_metaclass(CachedMetaClass, context.TreeContext)):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
if self.tree_node.type == 'lambda':
|
||||||
|
return LambdaName(self)
|
||||||
return ContextName(self, self.tree_node.name)
|
return ContextName(self, self.tree_node.name)
|
||||||
|
|
||||||
def get_param_names(self):
|
def get_param_names(self):
|
||||||
|
|||||||
@@ -609,7 +609,8 @@ class Function(ClassOrFunc):
|
|||||||
|
|
||||||
:rtype: str
|
:rtype: str
|
||||||
"""
|
"""
|
||||||
func_name = func_name or self.name
|
# Lambdas have no name.
|
||||||
|
func_name = func_name or getattr(self, 'name', '<lambda>')
|
||||||
code = unicode(func_name) + self._get_paramlist_code()
|
code = unicode(func_name) + self._get_paramlist_code()
|
||||||
return '\n'.join(textwrap.wrap(code, width))
|
return '\n'.join(textwrap.wrap(code, width))
|
||||||
|
|
||||||
@@ -639,13 +640,12 @@ class Lambda(Function):
|
|||||||
def __init__(self, children):
|
def __init__(self, children):
|
||||||
# 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)
|
||||||
lst = self.children[1:-2] # Everything between `lambda` and the `:` operator is a parameter.
|
# Everything between `lambda` and the `:` operator is a parameter.
|
||||||
self.children[1:-2] = _create_params(self, lst)
|
self.children[1:-2] = _create_params(self, self.children[1:-2])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
# Borrow the position of the <Keyword: lambda> AST node.
|
raise AttributeError("lambda is not named.")
|
||||||
return Name('<lambda>', self.children[0].start_pos)
|
|
||||||
|
|
||||||
def _get_paramlist_code(self):
|
def _get_paramlist_code(self):
|
||||||
return '(' + ''.join(param.get_code() for param in self.params).strip() + ')'
|
return '(' + ''.join(param.get_code() for param in self.params).strip() + ')'
|
||||||
@@ -664,6 +664,7 @@ class Lambda(Function):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def yields(self):
|
def yields(self):
|
||||||
|
# TODO rename
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
|||||||
@@ -36,8 +36,9 @@ class TestsFunctionAndLambdaParsing(object):
|
|||||||
return request.keywords['expected']
|
return request.keywords['expected']
|
||||||
|
|
||||||
def test_name(self, node, expected):
|
def test_name(self, node, expected):
|
||||||
assert isinstance(node.name, tree.Name)
|
if node.type != 'lambda':
|
||||||
assert unicode(node.name) == u(expected['name'])
|
assert isinstance(node.name, tree.Name)
|
||||||
|
assert unicode(node.name) == u(expected['name'])
|
||||||
|
|
||||||
def test_params(self, node, expected):
|
def test_params(self, node, expected):
|
||||||
assert isinstance(node.params, list)
|
assert isinstance(node.params, list)
|
||||||
|
|||||||
Reference in New Issue
Block a user