to pass self or not to pass self

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Wed Mar 17 15:51:53 CET 2010


Lie Ryan a écrit :
> On 03/17/2010 08:12 PM, Bruno Desthuilliers wrote:
>> Patrick Maupin a écrit :
>>> On Mar 16, 1:59 pm, Jason Tackaberry <t... at urandom.ca> wrote:
>>>> Why not create the bound methods at instantiation time, rather than
>>>> using the descriptor protocol which has the overhead of creating a new
>>>> bound method each time the method attribute is accessed?
>>> Well, for one thing, Python classes are open.  They can be added to at
>>> any time.  For another thing, you might not ever use most of the
>>> methods of an instance, so it would be a huge waste to create those.
>> A possible optimization would be a simple memoization on first access.
> 
> But what if, for example, one uses some descriptor/metaclass magic to
> make it so that each subsequent access to the attribute returns a method
> bound to different objects?

Well, that's the whole problem with dynamism vs optimization...



More information about the Python-list mailing list