Daniel Urban <urban.dani...@gmail.com> added the comment:

> Why is the exception normalized at the end? I suppose it's because
> when value is an exception instance, it's replaced by a tuple, but the
> original value has to be recreated at the end. So in some cases, the
> SyntaxError object is created twice...
>
> If PyErr_NormalizeException() can't be avoided, I suggest to call it
> at the start, just after PyErr_Fetch, and use the PySyntaxErrorObject*
> structure directly to get the file name and line numbers.

Yeah, it is because ast_error_finish creates a new tuple to use as the 
exception value.  (It creates a new (errstr, (filename, lineno, offset, loc)) 
tuple from the original (errstr, lineno, offset) tuple).  And yes, in some 
cases the SyntaxError instance is created twice.  I wasn't sure if it's okay to 
simply replace the args field of a PyBaseExceptionObject.  I don't know, if 
PyErr_NormalizeException() can be avoided, you wrote, that it "should probably 
normalize the exception as well".

Would it be better, if we, when got an exception instance, create the new tuple 
from the info, and replace the args field of the instance with it?  (But it 
also seems to me, that the SyntaxError objects have other fields as well, so 
probably we should modify them also.  That's why I thought that calling 
PyErr_NormalizeException with the new tuple is the simplest thing to do, 
becuase I guess that'll take care of all fields automatically.)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue11441>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to