Код: Выделить всё
class classproperty[T]:
def __init__(self, func: Callable[..., T]):
self.func = func
def __get__(self, _obj: Any, owner: Any) -> T:
return self.func(owner)
< /code>
Мой вопрос заключается в том, сможем ли мы сделать что -то лучше с набором? _obj
Код: Выделить всё
class classproperty[T, C]:
def __init__(self, func: Callable[[type[C]], T]):
self.func = func
def __get__(self, _obj: C, owner: type[C]) -> T:
return self.func(owner)
Код: Выделить всё
class Test:
@classproperty
def my_property(cls):
return 1
< /code>
Следующая ошибка < /p>
error: Argument 1 to "classproperty" has incompatible type "Callable[[Test], Any]"; expected "Callable[[type[Never]], Any]" [arg-type]
Подробнее здесь: https://stackoverflow.com/questions/795 ... -in-python