|
| 1 | +.. change:: |
| 2 | + :tags: bug, exceptions |
| 3 | + :tickets: 430, 245, 428 |
| 4 | + |
| 5 | + A series of fixes involving syntax warnings and exceptions found |
| 6 | + during template lexing / compilation: |
| 7 | + |
| 8 | + * Warnings raised while a template is compiled, which in practice means |
| 9 | + ``SyntaxWarning``, now report the filename and line number of the |
| 10 | + template rather than a line within the generated module, and are no |
| 11 | + longer reported twice. This applies equally to templates compiled from a |
| 12 | + string, from a file, and to a module file in a |
| 13 | + :paramref:`.Template.module_directory`, as does a warning raised while |
| 14 | + the module level code of a ``<%! %>`` block runs. Warnings raised while |
| 15 | + a template renders continue to report the location within the generated |
| 16 | + module. |
| 17 | + |
| 18 | + To do this, Mako replaces ``warnings.showwarning`` while a template is |
| 19 | + compiled. As that name is global to the process, an unrelated warning |
| 20 | + displayed by another thread during that window may also be passed through |
| 21 | + Mako's hook, which shows any warning it does not recognize unchanged. |
| 22 | + (:ticket:`430`) |
| 23 | + |
| 24 | + * The ``SyntaxException`` raised for a syntax error in Python code spanning |
| 25 | + several lines of a template, such as that within a ``<% %>`` or ``<%! %>`` |
| 26 | + block, is now reported against the line the error is on, rather than |
| 27 | + against the line on which the block begins. The line reported for code |
| 28 | + that occupies a single line, such as an expression or a control line, is |
| 29 | + unchanged. (:ticket:`245`) |
| 30 | + |
| 31 | + * The ``SyntaxException`` raised for a tag or expression that is never |
| 32 | + closed is now reported against the line the construct begins on, rather |
| 33 | + than the point at which the search for the closing token gave up, which |
| 34 | + for an unclosed construct is the end of the template. The message of the |
| 35 | + exception is amended to indicate that the position given is where the |
| 36 | + unterminated construct begins. (:ticket:`428`) |
| 37 | + |
| 38 | + |
| 39 | + |
0 commit comments