Class Methods Vs Any Other Callable
Arnaud Delobelle
arnodel at googlemail.com
Thu May 15 11:53:38 EDT 2008
Bruno Desthuilliers <bruno.42.desthuilliers at websiteburo.invalid> writes:
> FWIW, I wonder why the BDFL choosed to implement __new__ as a
> staticmethod - there are probably some pretty good reasons, but not
> knowing them, it looks like __new__ would have been a perfect
> candidate for a classmethod.
>
> So far, the only reason I can think of is that making it a classmethod
> would have required the use of super(Parent, cls) to call the parent's
> class __new__, which may (or may not - never had the case) be
> problematic (any guru on this ?)
Don't know but I remember something about this in 'Unifying types and
classes'. There it is:
Factoid: __new__ is a static method, not a class method. I
initially thought it would have to be a class method, and that's
why I added the classmethod primitive. Unfortunately, with class
methods, upcalls don't work right in this case, so I had to make
it a static method with an explicit class as its first
argument. Ironically, there are now no known uses for class
methods in the Python distribution (other than in the test
suite). I might even get rid of classmethod in a future release if
no good use for it can be found!
(http://www.python.org/download/releases/2.2/descrintro/)
I don't have the time to try to figure it out :(
--
Arnaud
More information about the Python-list
mailing list