[Python-ideas] from __past__ import division, str, etc

Chris Angelico rosuav at gmail.com
Thu Jan 9 00:38:15 CET 2014


On Thu, Jan 9, 2014 at 10:14 AM, Alejandro López Correa <alc at spika.net> wrote:
>> I'm pretty sure someone already wrote one of those - they're a
>> problem, because they mean the tracebacks for runtime exceptions don't
>> match the source code
>
> The idea is that exceptions that end up showing tracebacks should be,
> uhmm, exceptional (the tool should work 99.9% of the time and we are
> talking about working py2 code). When something happens, the problem
> of a different source in the traceback could be handled by the
> translation tool by adding annotations (even comments).

That's a sort-of-viable option (C preprocessors have used #line
directives for decades), but not really ideal. For it to work with
current Python, it would have to actually _be_  comments, so every
line would have to have something appended: # "file.py" 213

How would that behave on arbitrary code? What if there's backslash
continuation? Will people know to go looking elsewhere?

Exceptions DO happen. And when they do, the language should try to
make it easy to figure out what's going on. I'm not sure how well that
would be served by this, especially given that it's not supposed to be
a normal workflow. If you build a new language that uses Python as its
back-end, then manipulating the source code WOULD be the normal
workflow, and in that case I'd wholeheartedly support editing the
recorded line numbers (I think you can do that with AST
manipulation??) so tracebacks show the original file and line. But
this shouldn't be that normal.

ChrisA


More information about the Python-ideas mailing list