[issue11441] compile() raises SystemError if called from except clause

Daniel Urban report at bugs.python.org
Wed Mar 9 08:34:57 CET 2011


Daniel Urban <urban.dani+py at 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 <report at bugs.python.org>
<http://bugs.python.org/issue11441>
_______________________________________


More information about the Python-bugs-list mailing list