Commit cdb895f6 authored by Vitja Makarov's avatar Vitja Makarov

Fix lambda's default args, ticket #723

parent 155664e8
......@@ -5258,10 +5258,20 @@ class LambdaNode(InnerFunctionNode):
name = StringEncoding.EncodedString('<lambda>')
def analyse_declarations(self, env):
self.def_node.no_assignment_synthesis = True
self.def_node.pymethdef_required = True
self.def_node.analyse_declarations(env)
self.pymethdef_cname = self.def_node.entry.pymethdef_cname
env.add_lambda_def(self.def_node)
def analyse_types(self, env):
self.def_node.analyse_expressions(env)
super(LambdaNode, self).analyse_types(env)
def generate_result_code(self, code):
self.def_node.generate_execution_code(code)
super(LambdaNode, self).generate_result_code(code)
class GeneratorExpressionNode(LambdaNode):
# A generator expression, e.g. (i for i in range(10))
......@@ -5275,11 +5285,11 @@ class GeneratorExpressionNode(LambdaNode):
binding = False
def analyse_declarations(self, env):
self.def_node.no_assignment_synthesis = True
self.def_node.analyse_declarations(env)
super(GeneratorExpressionNode, self).analyse_declarations(env)
# No pymethdef required
self.def_node.pymethdef_required = False
# Force genexpr signature
self.def_node.entry.signature = TypeSlots.pyfunction_noargs
env.add_lambda_def(self.def_node)
def generate_result_code(self, code):
code.putln(
......
......@@ -1162,6 +1162,7 @@ class FuncDefNode(StatNode, BlockNode):
# entry Symtab.Entry
# needs_closure boolean Whether or not this function has inner functions/classes/yield
# needs_outer_scope boolean Whether or not this function requires outer scope
# pymethdef_required boolean Force Python method struct generation
# directive_locals { string : NameNode } locals defined by cython.locals(...)
# star_arg PyArgDeclNode or None * argument
# starstar_arg PyArgDeclNode or None ** argument
......@@ -1170,6 +1171,7 @@ class FuncDefNode(StatNode, BlockNode):
assmt = None
needs_closure = False
needs_outer_scope = False
pymethdef_required = False
is_generator = False
is_generator_body = False
modifiers = []
......@@ -1289,7 +1291,8 @@ class FuncDefNode(StatNode, BlockNode):
if preprocessor_guard:
code.putln(preprocessor_guard)
with_pymethdef = self.needs_assignment_synthesis(env, code)
with_pymethdef = (self.needs_assignment_synthesis(env, code) or
self.pymethdef_required)
if self.py_func:
self.py_func.generate_function_header(code,
with_pymethdef = with_pymethdef,
......
# mode: run
# ticket: 723
# tags: lambda
def t723(a):
"""
>>> t723(2)()
4
>>> t723(2)(3)
9
"""
return lambda x=a: x * x
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment