1

Consider the following code:

from module import some_function
class SomeClass:
    @staticmethod
    def class_function(*args, **kwargs):
        return some_function(*args, **kwargs)

The static method is simply an class wrapper to module.some_function. Why can't I do this with simple variable assignment.

from module import some_function
class SomeClass:
    class_function = some_function

Now, class_function is no longer a staticmethod, and also the decorator can't be used. Is there a way around this?

Cheers.

1 Answer 1

3

Use staticmethod the non-decorator way:

from module import some_function
class SomeClass:
    class_function = staticmethod(some_function)
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome. I knew it should be this way, just didn't know how wrap the decorator in a correct way. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.