aboutsummaryrefslogtreecommitdiffstats
path: root/mako/codegen.py
diff options
context:
space:
mode:
authorMartin von Gagern <gagern@google.com>2019-07-01 14:35:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-07-01 15:14:41 -0400
commit06d67cf4677e10e5c42581c02f293101e1c39a3a (patch)
treebf5355518d8b14d79fd822c357a14e29d2b575c7 /mako/codegen.py
parentf384df792ae5eeeaa4bd622191b3ca33d9b86a4d (diff)
downloadexternal_python_mako-06d67cf4677e10e5c42581c02f293101e1c39a3a.tar.gz
external_python_mako-06d67cf4677e10e5c42581c02f293101e1c39a3a.tar.bz2
external_python_mako-06d67cf4677e10e5c42581c02f293101e1c39a3a.zip
Correctly track line numbers for multi-line code blocks
Improved the line-number tracking for source lines inside of Python ``<% ... %>`` blocks, such that text- and HTML-formatted exception traces such as that of :func:`.html_error_template` now report the correct source line inside the block, rather than the first line of the block itself. Exceptions in ``<%! ... %>`` blocks which get raised while loading the module are still not reported correctly, as these are handled before the Mako code is generated. Pull request courtesy Martin von Gagern. Closes: #297 Pull-request: https://github.com/sqlalchemy/mako/pull/297 Pull-request-sha: 60ad749604f8de0a9b8133430995045a93d0939c Change-Id: I2086e4370e8e2db7099de01743840286f0160efc
Diffstat (limited to 'mako/codegen.py')
-rw-r--r--mako/codegen.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/mako/codegen.py b/mako/codegen.py
index 733d264..1acc5e6 100644
--- a/mako/codegen.py
+++ b/mako/codegen.py
@@ -354,8 +354,7 @@ class _GenerateRenderMethod(object):
"""write module-level template code, i.e. that which
is enclosed in <%! %> tags in the template."""
for n in module_code:
- self.printer.start_source(n.lineno)
- self.printer.write_indented_block(n.text)
+ self.printer.write_indented_block(n.text, starting_lineno=n.lineno)
def write_inherit(self, node):
"""write the module-level inheritance-determination callable."""
@@ -896,8 +895,9 @@ class _GenerateRenderMethod(object):
def visitCode(self, node):
if not node.ismodule:
- self.printer.start_source(node.lineno)
- self.printer.write_indented_block(node.text)
+ self.printer.write_indented_block(
+ node.text, starting_lineno=node.lineno
+ )
if not self.in_def and len(self.identifiers.locally_assigned) > 0:
# if we are the "template" def, fudge locally