Combining @staticmethod with other decorators is broken
See original GitHub issueConsider
def debug(fun):
print(fun)
return fun
class A(object):
@staticmethod
@debug
def foo(self):
return self
In Python, this correctly prints <function foo at 0x7f4d305df410>
.
In Cython, this wrongly prints <staticmethod object at 0x7f4d30e5e718>
.
When doing the same with a Cython cdef class
, the decorators are somehow applied twice: the output becomes
<staticmethod object at 0x7f4d30e5eb40>
<staticmethod object at 0x7f4d305e52f0>
Migrated from http://trac.cython.org/ticket/880
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:13 (4 by maintainers)
Top Results From Across the Web
python - Why can @decorator not decorate a staticmethod or a ...
classmethod and staticmethod return descriptor objects, not functions. Most decorators are not designed to accept descriptors.
Read more >no-staticmethod-decorator / R0203 - Pylint 2.16.0-dev ...
Consider using a decorator instead of calling staticmethod. Description: Used when a static method is defined without using the decorator syntax.
Read more >Python @staticmethod | How @staticmethod Decorator works
It is a method with no right to access or modify class state. The @staticmethod is a built-in function and simply returns a...
Read more >@classmethod and @staticmethod Method in Python - STechies
We hope this article has given you a clear idea between static and class methods and how they are different from each other....
Read more >Define Static Method using @staticmethod Decorator in Python
The @staticmethod is a built-in decorator that defines a static method in the class in Python. A static method doesn't receive any reference...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For peoplo who facing the same issue here, I got a method to work around this problem. convert a
to
A simple implementation of this kind of conversion using ast and astunparse is:
Hope this can help somebody.
FWIW there is a PR that should fix this issue https://github.com/cython/cython/pull/3966 - testing that PR and letting me know whether it works or not for your would be useful. We don’t really need more comments saying “I hope this is fixed soon” though.