File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change
1
+ .. change ::
2
+ :tags: bug, lexer
3
+ :tickets: 418
4
+
5
+ Fix undefined variable errors when ``strict_undefined=True `` when using a
6
+ nested list comprehension. Pull request courtesy Sébastien Granjoux.
7
+
Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ def visit_FunctionDef(self, node):
93
93
def visit_ListComp (self , node ):
94
94
if self .in_function :
95
95
for comp in node .generators :
96
+ self .visit (comp .target )
96
97
self .visit (comp .iter )
97
98
else :
98
99
self .generic_visit (node )
@@ -102,6 +103,7 @@ def visit_ListComp(self, node):
102
103
def visit_DictComp (self , node ):
103
104
if self .in_function :
104
105
for comp in node .generators :
106
+ self .visit (comp .target )
105
107
self .visit (comp .iter )
106
108
else :
107
109
self .generic_visit (node )
Original file line number Diff line number Diff line change @@ -916,6 +916,19 @@ def foo():
916
916
917
917
eq_ (result_lines (t .render ()), ["foo" ])
918
918
919
+ def test_nested_list_comprehensions_in_function_plus_undeclared_strict (
920
+ self ,
921
+ ):
922
+ t = Template (
923
+ """
924
+ <%foo = lambda b : sum(f for s in b for f in s)%>\
925
+ ${ foo(([1,2],[3,4]))}
926
+ """ ,
927
+ strict_undefined = True ,
928
+ )
929
+
930
+ eq_ (result_lines (t .render ()), ["10" ])
931
+
919
932
920
933
class StopRenderingTest (TemplateTest ):
921
934
def test_return_in_template (self ):
You can’t perform that action at this time.
0 commit comments