Commit 1057f3e0 authored by Vitja Makarov's avatar Vitja Makarov

Fix lambda's default args, ticket #723

--HG--
extra : transplant_source : %C8%BB%92%E3%5E%B7%C3z%7B%BA-%17%9D%2AA%ABO%84q%B7
parent 8230d3b9
...@@ -5233,10 +5233,20 @@ class LambdaNode(InnerFunctionNode): ...@@ -5233,10 +5233,20 @@ class LambdaNode(InnerFunctionNode):
name = StringEncoding.EncodedString('<lambda>') name = StringEncoding.EncodedString('<lambda>')
def analyse_declarations(self, env): 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.def_node.analyse_declarations(env)
self.pymethdef_cname = self.def_node.entry.pymethdef_cname self.pymethdef_cname = self.def_node.entry.pymethdef_cname
env.add_lambda_def(self.def_node) 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): class GeneratorExpressionNode(LambdaNode):
# A generator expression, e.g. (i for i in range(10)) # A generator expression, e.g. (i for i in range(10))
...@@ -5250,11 +5260,11 @@ class GeneratorExpressionNode(LambdaNode): ...@@ -5250,11 +5260,11 @@ class GeneratorExpressionNode(LambdaNode):
binding = False binding = False
def analyse_declarations(self, env): def analyse_declarations(self, env):
self.def_node.no_assignment_synthesis = True super(GeneratorExpressionNode, self).analyse_declarations(env)
self.def_node.analyse_declarations(env) # No pymethdef required
self.def_node.pymethdef_required = False
# Force genexpr signature # Force genexpr signature
self.def_node.entry.signature = TypeSlots.pyfunction_noargs self.def_node.entry.signature = TypeSlots.pyfunction_noargs
env.add_lambda_def(self.def_node)
def generate_result_code(self, code): def generate_result_code(self, code):
code.putln( code.putln(
......
...@@ -1163,6 +1163,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1163,6 +1163,7 @@ class FuncDefNode(StatNode, BlockNode):
# entry Symtab.Entry # entry Symtab.Entry
# needs_closure boolean Whether or not this function has inner functions/classes/yield # 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 # 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(...) # directive_locals { string : NameNode } locals defined by cython.locals(...)
# star_arg PyArgDeclNode or None * argument # star_arg PyArgDeclNode or None * argument
# starstar_arg PyArgDeclNode or None ** argument # starstar_arg PyArgDeclNode or None ** argument
...@@ -1171,6 +1172,7 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1171,6 +1172,7 @@ class FuncDefNode(StatNode, BlockNode):
assmt = None assmt = None
needs_closure = False needs_closure = False
needs_outer_scope = False needs_outer_scope = False
pymethdef_required = False
is_generator = False is_generator = False
is_generator_body = False is_generator_body = False
modifiers = [] modifiers = []
...@@ -1290,7 +1292,8 @@ class FuncDefNode(StatNode, BlockNode): ...@@ -1290,7 +1292,8 @@ class FuncDefNode(StatNode, BlockNode):
if preprocessor_guard: if preprocessor_guard:
code.putln(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: if self.py_func:
self.py_func.generate_function_header(code, self.py_func.generate_function_header(code,
with_pymethdef = with_pymethdef, 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