Hi,

On 28 August 2012 15:27, Sergiu Ivanov <[email protected]> wrote:

> Hello,
>
> While writing one of my classes, I needed to factor out some bits of
> functionality into private, instance-independent functions.  To avoid
> supplying any extra arguments to these functions, I have made them
> into static methods using the @staticmethod decorator.
>
> However, Tom has pointed out [0] that @classmethod would be preferable
> instead.  I have tried to google why that would be the case, but I
> haven't managed to dig anything out.  Grepping over the source of
> SymPy reveals the usage of @staticmethod on occasions almost as
> numerous as those where @classmethod is used.
>
> Is there a fixed strategy when to use one of the two decorators in
> SymPy?
>

classmethod decorator gives you the class as the first argument (cls) to a
method. Besides this it works the same as staticmethod. If you need the
class (e.g. to access other static methods/variables) then use classmethod.
Otherwise use staticmethod. Use `git grep -A 1 @classmethod` to see what
method signatures follow this decorator.


>
> Sergiu
>
> [0]
> https://github.com/scolobb/sympy/commit/603fd9e97f5b3215f3165f265a806b09fb80a830#sympy-categories-diagram_drawing-py-P6
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sympy?hl=en.
>
>
Mateusz

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to