> See this codes,
>
> 1 <h1>hello</h1>
> 2
> 3 <%
> 4 a = 5
> 5 a = b # error
> 6 %>
>
> traceback should point line 5, but it points line 3.
>
> mako/codegen.py may be the cause. here is visitCode method in
> codegen.py
>
> def visitCode(self, node):
> if not node.ismodule:
> self.write_source_comment(node)
> self.printer.write_indented_block(node.text)
>
> node contains whole python block, so write_source_comment is called
> only one time for one python block. If it is called by line, it can be
> fixed. However I don't understand 'node' object yet, I wasn't able to
> fix it.
I wouldn't want to fix it that way, as we'd need to fully parse and re-render the Python code within blocks which is an extremely complicated task and would greatly destabilize the code. Also there would be Python comments on every line, which itself would throw off line numbers and would also interfere with multiline statements.
It's a little tricky here but perhaps some extra directives in the comment would help, based on the type of node:
# SOURCE LINE 3 PYTHON_BLOCK
so that when we calculate the "line map", we know we can give successive template_ln assignments within the loop at exceptions.py line 170. Just a thought...
>
> There is one more problem. When using module level block, <%! %>, it
> doesn't even show error lines with
> exceptions.html_error_template().render()
this is a more complex issue. I'd consider working patches if they don't add excess complexity or any backwards incompatibility.
I wouldn't want to fix it that way, as we'd need to fully parse and re-render the Python code within blocks which is an extremely complicated task and would greatly destabilize the code. Also there would be Python comments on every line, which itself would throw off line numbers and would also interfere with multiline statements.
On Dec 21, 2011, at 2:32 PM, Youngrok Pak wrote:
> See this codes,
>
> 1 <h1>hello</h1>
> 2
> 3 <%
> 4 a = 5
> 5 a = b # error
> 6 %>
>
> traceback should point line 5, but it points line 3.
>
> mako/codegen.py may be the cause. here is visitCode method in
> codegen.py
>
> def visitCode(self, node):
> if not node.ismodule:
> self.write_source_comment(node)
> self.printer.write_indented_block(node.text)
>
> node contains whole python block, so write_source_comment is called
> only one time for one python block. If it is called by line, it can be
> fixed. However I don't understand 'node' object yet, I wasn't able to
> fix it.
It's a little tricky here but perhaps some extra directives in the comment would help, based on the type of node:
# SOURCE LINE 3 PYTHON_BLOCK
so that when we calculate the "line map", we know we can give successive template_ln assignments within the loop at exceptions.py line 170. Just a thought...
# calculate line number offset for python block
lineno_offset = 0
if template_line.startswith('<%'):
while line_map[lineno - lineno_offset] == template_ln:
lineno_offset += 1
template_ln = template_ln + lineno_offset - 1
if template_ln <= len(template_lines):
template_line = template_lines[template_ln - 1]
else:
template_line = None
>this is a more complex issue. I'd consider working patches if they don't add excess complexity or any backwards incompatibility.
> There is one more problem. When using module level block, <%! %>, it
> doesn't even show error lines with
> exceptions.html_error_template().render()
--
You received this message because you are subscribed to the Google Groups "Mako Templates for Python" group.
To post to this group, send email to mako-d...@googlegroups.com.
To unsubscribe from this group, send email to mako-discuss...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mako-discuss?hl=en.
I see your point. However, you may not need to specify the type of node in comment. What if use the condition template_line.startswith('<%') ?
The code looks somewhat ugly, but it worked for me. If you wish, I'll send pull request through github.