Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Nick Coghlan
On 8 Nov 2013 04:44, "Brett Cannon" wrote: > On Thu, Nov 7, 2013 at 7:41 AM, Nick Coghlan wrote: >> >> The bigger problem is you can't change the constructor signature in a backwards incompatible way. You would need a new class method as an alternative constructor instead, or else use optional pa

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Brett Cannon
On Thu, Nov 7, 2013 at 2:20 PM, Eric Snow wrote: > On Thu, Nov 7, 2013 at 11:44 AM, Brett Cannon 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)

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Eric Snow
On Thu, Nov 7, 2013 at 11:44 AM, Brett Cannon 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): ac

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Brett Cannon
On Thu, Nov 7, 2013 at 7:41 AM, Nick Coghlan wrote: > > On 7 Nov 2013 21:34, "Victor Stinner" wrote: > > > > 2013/11/7 Steven D'Aprano : > > > My initial instinct here was to say that sounded like premature > > > optimization, but to my surprise the overhead of generating the error > > > message

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Nick Coghlan
On 7 Nov 2013 21:34, "Victor Stinner" wrote: > > 2013/11/7 Steven D'Aprano : > > My initial instinct here was to say that sounded like premature > > optimization, but to my surprise the overhead of generating the error > > message is actually significant -- at least from pure Python 3.3 code. > >

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Serhiy Storchaka
07.11.13 00:32, Victor Stinner написав(ла): I'm trying to avoid unnecessary temporary Unicode strings when possible (see issue #19512). While working on this, I saw that Python likes preparing an user friendly message to explain why getting an attribute failed. The problem is that in most cases,

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-07 Thread Victor Stinner
2013/11/7 Steven D'Aprano : > My initial instinct here was to say that sounded like premature > optimization, but to my surprise the overhead of generating the error > message is actually significant -- at least from pure Python 3.3 code. I ran a quick and dirty benchmark by replacing the error me

Re: [Python-Dev] Avoid formatting an error message on attribute error

2013-11-06 Thread Steven D'Aprano
On Wed, Nov 06, 2013 at 11:32:33PM +0100, Victor Stinner wrote: > Hi, > > I'm trying to avoid unnecessary temporary Unicode strings when > possible (see issue #19512). While working on this, I saw that Python > likes preparing an user friendly message to explain why getting an > attribute failed.

[Python-Dev] Avoid formatting an error message on attribute error

2013-11-06 Thread Victor Stinner
Hi, I'm trying to avoid unnecessary temporary Unicode strings when possible (see issue #19512). While working on this, I saw that Python likes preparing an user friendly message to explain why getting an attribute failed. The problem is that in most cases, the caller doesn't care of the message: t