Making a decorator a staticmethod

Jonathan Gardner jgardner at jonathangardner.net
Thu Jan 8 14:57:54 EST 2009


On Jan 8, 11:18 am, "Zac Burns" <zac... at gmail.com> wrote:
>
> In my use case (not the example below) the decorator returns a
> function of the form def f(self, *args, **kwargs) which makes use of
> attributes on the instance self. So, it only makes sense to use the
> staticmethod in the class and in the baseclass. Making this decorator
> a module level function doesn't make sense here.
>

I don't think you should be using staticmethod in this case since you
are relying on information in the class itself. This really looks like
it should be a classmethod. Granted, the example you gave can be a
staticmethod, but it sounds like you want to incorporate some of the
information in the class.

(Aside: I really can't think of any reason to use staticmethods in
Python other than to organize functions into namespaces, and even
then, that's what modules are for, right?)

I think you need to show a better example of what it is you are trying
to do.



More information about the Python-list mailing list