[Python-Dev] Avoid formatting an error message on attribute error
brett at python.org
Thu Nov 7 20:33:31 CET 2013
On Thu, Nov 7, 2013 at 2:20 PM, Eric Snow <ericsnowcurrently at gmail.com>wrote:
> On Thu, Nov 7, 2013 at 11:44 AM, Brett Cannon <brett at python.org> wrote:
> > Lazy message creation through
> > __str__ does leave the message out of `args`, though.
> If that's an issue you could make args a (settable) property that
> dynmically returns str(self) if appropriate:
> def args(self):
> actual = super().args
> if actual or self.name is None:
> return actual
> return (str(self),)
Good point. That would solve that backwards-compatibility issue and allow
the raising of DeprecationWarning.
> > In a perfect world (Python 4 maybe?) BaseException would take a single
> > argument which would be an optional message, `args` wouldn't exist, and
> > people called `str(exc)` to get the message for the exception. That would
> > allow subclasses to expand the API with keyword-only arguments to carry
> > extra info and have reasonable default messages that were built on-demand
> > when __str__ was called. It would also keep `args` from just being a
> > ground of stuff that has no structure except by calling convention
> (which is
> > not how to do an API; explicit > implicit and all). IOW the original
> > of PEP 352 (http://python.org/dev/peps/pep-0352/#retracted-ideas).
> This reminds me that I need to revisit that idea of reimplementing all
> the builtin exceptions in pure Python. :)
Ah, that idea. =) Definitely a question of performance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev