Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 MAINTAIN: Improve type annotations of @classproperty #5176

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions aiida/common/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import functools
import inspect
import keyword
from typing import Any, Callable, Generic, TypeVar


def isidentifier(identifier):
Expand Down Expand Up @@ -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]):
chrisjsewell marked this conversation as resolved.
Show resolved Hide resolved
"""
A class that, when used as a decorator, works as if the
two decorators @property and @classmethod where applied together
Expand All @@ -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)
1 change: 1 addition & 0 deletions docs/source/nitpick-exceptions
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down