Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Terry Reedy
On 8/13/2014 5:51 AM, Chris Angelico wrote: On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: When I assign the reference as a class variable, the reference has __self__ set, too, so I get an extra argument passed to the function. If I assign the reference as an instance variable, then __self__ is

Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 11:12 PM, Steven D'Aprano wrote: > Chris Angelico wrote: > >> The bound method object stores a reference to the original object (the >> thing that becomes the first argument to the target function) in >> __self__ (and the function in __func__). ISTM this ought to be _self >

Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Steven D'Aprano
Chris Angelico wrote: > The bound method object stores a reference to the original object (the > thing that becomes the first argument to the target function) in > __self__ (and the function in __func__). ISTM this ought to be _self > (and _func), as it's intended to be private; Why do you say th

Re: Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Ned Batchelder
On 8/13/14 5:51 AM, Chris Angelico wrote: On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: When I assign the reference as a class variable, the reference has __self__ set, too, so I get an extra argument passed to the function. If I assign the reference as an instance variable, then __self__ is u

Re: odd difference calling function from class or instance variable

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 8:20 PM, GregS wrote: > Thanks to both of you for your incredibly prompt replies. My homework for > tonight is to digest the descriptor protocol... > > Peter, thanks for suggesting using staticmethod() to get the behaviour I was > expecting. I've only used staticmethod as

Re: odd difference calling function from class or instance variable

2014-08-13 Thread GregS
Thanks to both of you for your incredibly prompt replies. My homework for tonight is to digest the descriptor protocol... Peter, thanks for suggesting using staticmethod() to get the behaviour I was expecting. I've only used staticmethod as a decorator before now. Chris, I agree that it's n

Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: > When I assign the reference as a class variable, the reference has __self__ > set, too, so I get an extra argument passed to the function. If I assign > the reference as an instance variable, then __self__ is unset so no extra > argument. Spin-off

Re: odd difference calling function from class or instance variable

2014-08-13 Thread Chris Angelico
On Wed, Aug 13, 2014 at 7:06 PM, GregS wrote: > If you look at i.ref.__self__ for the two cases, you'll see what's going on. > I've tried RTFMing but can't find the reason for the two behaviours. Could > someone provide an explanation for me, please? What you're seeing there is the magic of inst

Re: odd difference calling function from class or instance variable

2014-08-13 Thread Peter Otten
GregS wrote: > Hello, > > This is my first post here so please gently inform me of any etiquette > breaches. > > I'm seeing a behaviour I can't explain with Python 3.4.1 when I call a > function via a reference stored in an object. > > When I assign the reference as a class variable, the refere