diff --git a/aiida/common/lang.py b/aiida/common/lang.py index f2bb8906f6..37f977b8b9 100644 --- a/aiida/common/lang.py +++ b/aiida/common/lang.py @@ -11,6 +11,7 @@ import functools import inspect import keyword +from typing import Any, Callable, Generic, TypeVar def isidentifier(identifier): @@ -75,8 +76,10 @@ def wrapped_fn(self, *args, **kwargs): # pylint: disable=missing-docstring override = override_decorator(check=False) # pylint: disable=invalid-name +ReturnType = TypeVar('ReturnType') -class classproperty: # pylint: disable=invalid-name + +class classproperty(Generic[ReturnType]): # pylint: disable=invalid-name """ A class that, when used as a decorator, works as if the two decorators @property and @classmethod where applied together @@ -85,8 +88,8 @@ class classproperty: # pylint: disable=invalid-name instance as its first argument). """ - def __init__(self, getter): + def __init__(self, getter: Callable[[Any], ReturnType]) -> None: self.getter = getter - def __get__(self, instance, owner): + def __get__(self, instance: Any, owner: Any) -> ReturnType: return self.getter(owner) diff --git a/docs/source/nitpick-exceptions b/docs/source/nitpick-exceptions index 99af999ad5..44cf0958fc 100644 --- a/docs/source/nitpick-exceptions +++ b/docs/source/nitpick-exceptions @@ -21,6 +21,7 @@ py:class builtins.dict # typing py:class asyncio.events.AbstractEventLoop py:class EntityType +py:class ReturnType py:class function py:class IO py:class traceback