|
1 | 1 | # mako/codegen.py |
2 | | -# Copyright 2006-2020 the Mako authors and contributors <see AUTHORS file> |
| 2 | +# Copyright 2006-2021 the Mako authors and contributors <see AUTHORS file> |
3 | 3 | # |
4 | 4 | # This module is part of Mako and is released under |
5 | 5 | # the MIT License: http://www.opensource.org/licenses/mit-license.php |
|
12 | 12 | import time |
13 | 13 |
|
14 | 14 | from mako import ast |
15 | | -from mako import compat |
16 | 15 | from mako import exceptions |
17 | 16 | from mako import filters |
18 | 17 | from mako import parsetree |
|
25 | 24 | # names which are hardwired into the |
26 | 25 | # template and are not accessed via the |
27 | 26 | # context itself |
28 | | -TOPLEVEL_DECLARED = set(["UNDEFINED", "STOP_RENDERING"]) |
29 | | -RESERVED_NAMES = set(["context", "loop"]).union(TOPLEVEL_DECLARED) |
| 27 | +TOPLEVEL_DECLARED = {"UNDEFINED", "STOP_RENDERING"} |
| 28 | +RESERVED_NAMES = {"context", "loop"}.union(TOPLEVEL_DECLARED) |
30 | 29 |
|
31 | 30 |
|
32 | 31 | def compile( # noqa |
@@ -393,7 +392,7 @@ def visitDefOrBase(s, node): |
393 | 392 | raise exceptions.CompileException( |
394 | 393 | "Can't put anonymous blocks inside " |
395 | 394 | "<%namespace>", |
396 | | - **node.exception_kwargs |
| 395 | + **node.exception_kwargs, |
397 | 396 | ) |
398 | 397 | self.write_inline_def(node, identifiers, nested=False) |
399 | 398 | export.append(node.funcname) |
@@ -470,7 +469,7 @@ def write_variable_declares(self, identifiers, toplevel=False, limit=None): |
470 | 469 | """ |
471 | 470 |
|
472 | 471 | # collection of all defs available to us in this scope |
473 | | - comp_idents = dict([(c.funcname, c) for c in identifiers.defs]) |
| 472 | + comp_idents = {c.funcname: c for c in identifiers.defs} |
474 | 473 | to_write = set() |
475 | 474 |
|
476 | 475 | # write "context.get()" for all variables we are going to |
@@ -846,11 +845,11 @@ def visitControlLine(self, node): |
846 | 845 | # and end control lines, and |
847 | 846 | # 3) any control line with no content other than comments |
848 | 847 | if not children or ( |
849 | | - compat.all( |
| 848 | + all( |
850 | 849 | isinstance(c, (parsetree.Comment, parsetree.ControlLine)) |
851 | 850 | for c in children |
852 | 851 | ) |
853 | | - and compat.all( |
| 852 | + and all( |
854 | 853 | (node.is_ternary(c.keyword) or c.isend) |
855 | 854 | for c in children |
856 | 855 | if isinstance(c, parsetree.ControlLine) |
@@ -1157,7 +1156,7 @@ def _check_name_exists(self, collection, node): |
1157 | 1156 | raise exceptions.CompileException( |
1158 | 1157 | "%%def or %%block named '%s' already " |
1159 | 1158 | "exists in this template." % node.funcname, |
1160 | | - **node.exception_kwargs |
| 1159 | + **node.exception_kwargs, |
1161 | 1160 | ) |
1162 | 1161 |
|
1163 | 1162 | def visitDefTag(self, node): |
@@ -1187,15 +1186,15 @@ def visitBlockTag(self, node): |
1187 | 1186 | raise exceptions.CompileException( |
1188 | 1187 | "Named block '%s' not allowed inside of def '%s'" |
1189 | 1188 | % (node.name, self.node.name), |
1190 | | - **node.exception_kwargs |
| 1189 | + **node.exception_kwargs, |
1191 | 1190 | ) |
1192 | 1191 | elif isinstance( |
1193 | 1192 | self.node, (parsetree.CallTag, parsetree.CallNamespaceTag) |
1194 | 1193 | ): |
1195 | 1194 | raise exceptions.CompileException( |
1196 | 1195 | "Named block '%s' not allowed inside of <%%call> tag" |
1197 | 1196 | % (node.name,), |
1198 | | - **node.exception_kwargs |
| 1197 | + **node.exception_kwargs, |
1199 | 1198 | ) |
1200 | 1199 |
|
1201 | 1200 | for ident in node.undeclared_identifiers(): |
|
0 commit comments