Skip to content

Commit

Permalink
Fix @reify type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
atugushev committed May 11, 2020
1 parent bfc25dd commit 6e4335f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Callable,
Dict,
Generator,
Generic,
Iterable,
Iterator,
List,
Expand Down Expand Up @@ -79,6 +80,7 @@ def all_tasks(


_T = TypeVar('_T')
_S = TypeVar('_S')


sentinel = object() # type: Any
Expand Down Expand Up @@ -382,7 +384,7 @@ def is_expected_content_type(response_content_type: str,
return expected_content_type in response_content_type


class reify:
class reify(Generic[_T):
"""Use as a class method decorator. It operates almost exactly like
the Python `@property` decorator, but it puts the result of the
method it decorates into the instance dict after the first call,
Expand All @@ -391,12 +393,12 @@ class reify:
"""

def __init__(self, wrapped: Callable[..., Any]) -> None:
def __init__(self, wrapped: Callable[..., _T]) -> None:
self.wrapped = wrapped
self.__doc__ = wrapped.__doc__
self.name = wrapped.__name__

def __get__(self, inst: Any, owner: Any) -> Any:
def __get__(self, inst: _S, owner: Optional[Type[Any]] = None) -> _T:
try:
try:
return inst._cache[self.name]
Expand All @@ -409,7 +411,7 @@ def __get__(self, inst: Any, owner: Any) -> Any:
return self
raise

def __set__(self, inst: Any, value: Any) -> None:
def __set__(self, inst: _S, value: _T) -> None:
raise AttributeError("reified property is read-only")


Expand Down

0 comments on commit 6e4335f

Please sign in to comment.