[Python-Dev] Avoid formatting an error message on attribute error (original) (raw)
Brett Cannon brett at python.org
Thu Nov 7 20:33:31 CET 2013
- Previous message: [Python-Dev] Avoid formatting an error message on attribute error
- Next message: [Python-Dev] Avoid formatting an error message on attribute error
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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: @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 calledstr(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 keepargs
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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20131107/05498b85/attachment.html>
- Previous message: [Python-Dev] Avoid formatting an error message on attribute error
- Next message: [Python-Dev] Avoid formatting an error message on attribute error
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]