static method feature
rashkatsa at wanadoo.fr
Tue Nov 25 16:57:20 CET 2003
do you know why python development team decided to forbid polymorphism
for static methods ? As you can do it in another languages (Java,...) it
could be very handy if you can create utility classes with static
methods that could be differentiate from the number of parameters.
with no static methods, it is already possible in python :
but as soon as you use static :
# here you can't declare agin the same
# assignment : assertEquals=staticmethod(assertEquals)
# because they only differ from the number of parameters
several design solutions :
1) It could be possible to extend staticmethod(function) to
staticmethod(function, arity) and resolve during call with the len of
arguments pass to the function (we could imagine that default parameter
are not allowed : it is the price for the speed :))
2) You could add a new key in the language (defstatic for example) like
in the following :
but you will now have two keywords for methods definition
3) The best seems to add a method attribute like static before def keyword.
what is your opinion ?
More information about the Python-list