For best performance (reduce time to build an exception object), I
would be interested to only format the error message on demand. For
example, when str(exception) is called.
The problem is the Exception.args attribute. Example:
$ ./python
Python 3.10.0a6+
>>> exc=AttributeError("%s object has no attribute %s" % ("MyObject", "name"))
>>> str(exc)
'MyObject object has no attribute name'
>>> exc.args
('MyObject object has no attribute name',)
Currently, args is the raw positional arguments passed to the
Exception constructor, and they are very likely many applications
relying on Exception.args.
For backward compatibility, we could store "%s object has no attribute
%s" and ("MyObject", "name"), and build the args tuple on demand and
format the string at the first str() call.
At the C level, args is exposed directly as PyBaseExceptionObject.args
and the PyBaseExceptionObject structure is part of the public C API.
Changing it would be a C API incompatible change.
By the way, the PEP 473 doesn't say anything about it and has no
"Backward compatibility" section :-(
Victor
On Sat, Mar 13, 2021 at 7:49 PM Sebastian Kreft <
skr...@gmail.com> wrote:
>
> Message archived at
https://mail.python.org/archives/list/pytho...@python.org/message/4XVFFNBHXN5KBTHJGMX6ZTN6KOW4Z7UG/
--
Night gathers, and now my watch begins. It shall not end until my death.
Message archived at
https://mail.python.org/archives/list/pytho...@python.org/message/LVI7S6O5QVVTZN5A6DLYHEKGHW6EIZUH/