Confused with methods

Alex Martelli aleaxit at yahoo.com
Mon Feb 7 10:54:09 EST 2005


John Lenton <john at grulic.org.ar> wrote:

> I think __new__ being an
> exception to this is a (minor) wart, in fact it feels like premature
> optimization (how many __new__s do you write, that you can't stick a
> @staticmethod in front of them?

I personally think it's quite reasonable for Python's infrastructure to
consider each special name specially -- that's what the double
underscores before and after are FOR, after all.  Since __new__ MUST be
a staticmethod, and there's no use case for it ever being otherwise, it
seems quite sensible for the default metaclass to MAKE it a staticmethod
(and otherwise treat it specially, as it needs to be).  I don't see what
optimization has to do with it (quite apart from the fact that __new__
was introduced before the splatsyntax for decorators, so that rather
than sticking anything in front the alternative would have been to
demand serious boilerplate, a '__new__ = staticmethod(__new__)' after
every definition of such a method).  Reducing boilerplate with no ill
effects whatsoever seems quite a worthy goal to me, when reachable.


Alex



More information about the Python-list mailing list