diff --git a/doc/build/unreleased/398.rst b/doc/build/unreleased/398.rst new file mode 100644 index 0000000..c7104a3 --- /dev/null +++ b/doc/build/unreleased/398.rst @@ -0,0 +1,6 @@ +.. change:: + :tags: bug, parser + :tickets: 398 + + Fixed the fix for ticket 320. It was trigerring an error in dictionary + comprehension when the key is not a simple name. diff --git a/mako/pyparser.py b/mako/pyparser.py index b25ef6e..714e004 100644 --- a/mako/pyparser.py +++ b/mako/pyparser.py @@ -92,8 +92,6 @@ def visit_FunctionDef(self, node): def visit_ListComp(self, node): if self.in_function: - if not isinstance(node.elt, _ast.Name): - self.visit(node.elt) for comp in node.generators: self.visit(comp.iter) else: @@ -103,8 +101,6 @@ def visit_ListComp(self, node): def visit_DictComp(self, node): if self.in_function: - if not isinstance(node.key, _ast.Name): - self.visit(node.elt) for comp in node.generators: self.visit(comp.iter) else: diff --git a/setup.cfg b/setup.cfg index f643d01..ecbbe0f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -89,7 +89,7 @@ show-source = true enable-extensions = G # E203 is due to https://github.com/PyCQA/pycodestyle/issues/373 ignore = - A003, + A003,A005 D, E203,E305,E711,E712,E721,E722,E741, N801,N802,N806, diff --git a/test/test_template.py b/test/test_template.py index 34598d2..4ab60d8 100644 --- a/test/test_template.py +++ b/test/test_template.py @@ -878,6 +878,21 @@ def test_list_comprehensions_plus_undeclared_strict(self): eq_(result_lines(t.render(t="T")), ["t is: T", "a,b,c"]) + def test_dict_comprehensions_in_function_plus_undeclared_strict(self): + t = Template( + """ +<% + def foo(): + return {s[0]: s for s in ('foo',)} +%> + +${ foo()['f'] } +""", + strict_undefined=True, + ) + + eq_(result_lines(t.render()), ["foo"]) + class StopRenderingTest(TemplateTest): def test_return_in_template(self):