Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
cocolato committed Feb 1, 2024
1 parent 7a012f5 commit daffd38
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
6 changes: 3 additions & 3 deletions mako/pyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def visit_Lambda(self, node, *args):
def visit_FunctionDef(self, node):
self._add_declared(node.name)
self._visit_function(node, False)

def visit_ListComp(self, node):
if self.in_function:
if not isinstance(node.elt, _ast.Name):
Expand All @@ -98,9 +98,9 @@ def visit_ListComp(self, node):
self.visit(comp.iter)
else:
self.generic_visit(node)

visit_SetComp = visit_GeneratorExp = visit_ListComp

def visit_DictComp(self, node):
if self.in_function:
if not isinstance(node.key, _ast.Name):
Expand Down
6 changes: 3 additions & 3 deletions test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def test_locate_identifiers_17(self):
"""
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.undeclared_identifiers, {"x", "y", "Foo", "Bar"})

def test_locate_identifiers_18(self):
code = """
def func():
Expand All @@ -230,7 +230,7 @@ def func():
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.declared_identifiers, {"func"})
eq_(parsed.undeclared_identifiers, {"range"})

def test_locate_identifiers_19(self):
code = """
def func():
Expand All @@ -239,7 +239,7 @@ def func():
parsed = ast.PythonCode(code, **exception_kwargs)
eq_(parsed.declared_identifiers, {"func"})
eq_(parsed.undeclared_identifiers, {"range"})

def test_locate_identifiers_20(self):
code = """
def func():
Expand Down
29 changes: 15 additions & 14 deletions test/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,6 @@ def test_inline_percent(self):
"bar %% baz",
]


def test_lsitcomp_in_func_strict(self):
t = Template(
"""
Expand All @@ -1729,10 +1728,11 @@ def getkeys(x):
%>
${ ','.join( getkeys(mydict) ) }
"""
, strict_undefined=True)
""",
strict_undefined=True,
)
assert result_raw_lines(t.render()) == ["foo"]

def test_setcomp_in_func_strict(self):
t = Template(
"""
Expand All @@ -1743,11 +1743,11 @@ def getkeys(x):
%>
${ ','.join( getkeys(mydict) ) }
"""
, strict_undefined=True)
""",
strict_undefined=True,
)
assert result_raw_lines(t.render()) == ["foo"]



def test_generator_in_func_strict(self):
t = Template(
"""
Expand All @@ -1758,11 +1758,11 @@ def getkeys(x):
%>
${ ','.join( getkeys(mydict) ) }
"""
, strict_undefined=True)
""",
strict_undefined=True,
)
assert result_raw_lines(t.render()) == ["foo"]



def test_dictcomp_in_func_strict(self):
t = Template(
"""
Expand All @@ -1772,6 +1772,7 @@ def square():
%>
${ square()[3] }
"""
, strict_undefined=True)
""",
strict_undefined=True,
)
assert result_raw_lines(t.render()) == ["9"]

0 comments on commit daffd38

Please sign in to comment.