[Zope-Coders] new.instancemethod behavior under py22 vs. py21
Chris McDonough
chrism@zope.com
04 Jun 2003 11:31:01 -0400
On Wed, 2003-06-04 at 06:58, Guido van Rossum wrote:
> The difference is that in 2.1, new.instancemethod is a factory
> function that does more strict typechecking than it needs to. In 2.2,
> new.instancemethod is the corresponding type itself, and its
> constructor does only the minimum needed type checking (it checks that
> the first argument is callable, and that's it). In 2.1, new is a C
> module; in 2.2, new is a Python module containing about 5 lines of
> code. :-)
Thanks for the explanation... nifty. ;-)
> Assuming you really don't want the function to become a permanent
> method of the class, you can do the following for regular classes:
>
> anextensionclass._func = afunction
> bound_method = anextensionclass._func
> del anextensionclass._func
>
> I don't know if that works for ExtensionClasses but if it does, it may
> be simpler than the solution you describe in your own followup. Or
> not (the temporary assignment is a gross hack of course).
Because the instance is persistent, rebinding via assignment is a bit
complicated, so I think the ExtensionClass magic solution is better in
this case...
Thanks,
- C