Python: keep 'cls' annotation for custom classmethod implementation

Viewed 164

So what i created at first was my own implementation of class-property. It behaves like normal property, but actually applied to a class:

class classproperty(property):
    def __get__(self, cls, owner):
        return classmethod(self.fget).__get__(None, owner)()

class A:
    @classproperty
    def f(cls):
        return 1

It works just fine, but PyCharm highlights cls and says that "Usually first parameter of a method is named 'self' ".

enter image description here

The question is: is there any way to tell PyCharm/interpreter, that @classproperty is actually a sort of classmethod and that i want to preserve cls as name for first parameter?

I've tried setting metaclass=classmethod, but that caused TypeError: metaclass conflict. Making classproprty to extend both inherit both property and classmethod also gave me TypeError: multiple bases have instance lay-out conflict which is kind of expected.

So can i trick it into thinking that my decorator is a kind of classmethod?

0 Answers
Related