On Thu, Nov 7, 2013 at 2:20 PM, Eric Snow <ericsnowcurren...@gmail.com>wrote:

> On Thu, Nov 7, 2013 at 11:44 AM, Brett Cannon <br...@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:
>
>     @property
>     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
> dumping
> > 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
> dream
> > 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.
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to