A friend, Antoine Rozo, wrote a variant of staticmethod which is
callable. With this decorator, it works in A, B and C cases:
---
class simplefunction:
    def __init__(self, func):
        self.func = func
    def __get__(self, owner, instance):
        return self.func
    def __call__(self, *args, **kwargs):
        return self.func(*args, **kwargs)

@simplefunction
def func():
    print("my func")

class MyClass:
    method = func

func() # A
MyClass.method() # B
MyClass().method() # C
---

It works without the __get__() method, but in this case, we go through
the __call__() indirection for A, B and C cases, rather than only
going through __call__() indirection in A case.

Victor
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OQUM4RZBIGHF6UJYQDFAMTHOZOU5DLKS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to