Question regarding __new__

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Fri Mar 23 04:00:29 EDT 2007


En Thu, 22 Mar 2007 13:19:52 -0300, Frank Benkstein  
<frank-python at benkstein.net> escribió:

> Yet [1] says: "[...] some rules for __new__: [...] If you return an
> object of a different class, its __init__ method will be called."

That was true at that time (2.2 initial), but not now. See  
http://www.python.org/sf/537450
Revision 26220 - Modified Sat Apr 6 01:05:01 2002 UTC (4 years, 11 months  
ago) by gvanrossum
- Changed new-style class instantiation so that when C's __new__
   method returns something that's not a C instance, its __init__ is
   not called.  [SF bug #537450]

The documentation should be updated to reflect this change.

> Am I missing something? Is this documented somewhere else?

See http://docs.python.org/ref/customization.html

> Also it
> would be nice if someone could point me to the function that implements
> this in C. I didn't find anything in object.c or typeobject.c.

It's in typeobject.c, function type_call

-- 
Gabriel Genellina




More information about the Python-list mailing list