importing a method
aleax at mail.comcast.net
Thu Dec 1 04:20:32 CET 2005
Martin Miller <ggrp1.20.martineau at dfgh.net> wrote:
> You're not missing anything -- it's my own [mis-]understanding that
> descriptors would only work with new-style classes, not the old-style
> ones used in the OP's example.
> However your example certainly proves that is not the case, even if you
> go one step further and call the bound method/function:
> >>> o.z()
> <__main__.old instance at 0x009D5F30>
> So I stand corrected -- thank you.
You're welcome. Your previous misunderstanding may be due to the fact
that (differently from __get__) the special method __set__ doesn't work
when the descriptor is held in an old-style class... to be more precise,
it's not even given a chance, since assigning to an instance attribute
(where the instance's old-style) just blithely sets the value in the
instance's __dict__, without even checking for the existence of a
descriptor by that name in the class.
More information about the Python-list