#line in python

R

Ross Boylan

The ast module shows that elements of the syntax tree have line and
column numbers. Would it be sensible to attempt to revise them to
achieve effects like the #line directive in C?

Context: Using noweb, a literate programming tool, which from a source
file foo.nw produces foo.py. The lines in the two files may be in
completely different sequenes. For debugging, it is useful to receive
error reports that refer to the original line number in foo.nw.

I am not sure how such rewriting would interact with debugger commands
that set a breakpoint at a file and line number. I'm also not sure it
would change the reported line numbers of errors.

The lack of a file name could be problematic if multiple sources
contributed to the same .py file, but that is an unlikely scenario.

As an extension or alternate, could there be a decorator like
@source_line(lineno, filename)
for classes and methods that could do the conversion on the fly? I
don't know if there's a way to go from the function (or class) object
the decorator receives to the AST.

Comments?

Ross Boylan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top