@staticmethod, backward compatibility?

Peter Hansen peter at engcorp.com
Tue Sep 27 14:05:28 CEST 2005


Neal Becker wrote:
> How can I write code to take advantage of new decorator syntax, while
> allowing backward compatibility?
> 
> I almost want a preprocessor.
> 
> #if PYTHON_VERSION >= 2.4
> @staticmethod
> ...
> 
> Since python < 2.4 will just choke on @staticmethod, how can I do this?

It seems to me that no matter what you do, if it's not done with an 
external processing tool which requires no changes in the source code, 
the result will be much uglier than if you just used the pre-2.4 
decorator syntax:

    def meth():
       pass
    meth = staticmethod(meth)


-Peter



More information about the Python-list mailing list