original) (raw)
(On Thu, Nov 7, 2013 at 2:20 PM, Eric Snow <ericsnowcurrently@gmail.com> wrote:
On Thu, Nov 7, 2013 at 11:44 AM, Brett Cannon <brett@python.org> wrote:If that's an issue you could make args a (settable) property that
> Lazy message creation through
> __str__ does leave the message out of `args`, though.
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.
This reminds me that I need to revisit that idea of reimplementing all
\>
\> 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).
the builtin exceptions in pure Python. :)
Ah, that idea. =) Definitely a question of performance.