Skip to content

Commit

Permalink
Merge pull request #1199 from PokestarFan/add-types-cache
Browse files Browse the repository at this point in the history
(#1164) Add types to cache.py
  • Loading branch information
bboe committed Dec 29, 2019
2 parents 5c29aa3 + 9a9dbd8 commit 31b441f
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions praw/util/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Caching utilities."""
from typing import Any, Callable, Optional


class cachedproperty:
Expand All @@ -18,15 +19,17 @@ class cachedproperty:
.. versionadded:: 6.3.0
"""

def __init__(self, func, doc=None):
def __init__(self, func: Callable[[Any], Any], doc: Optional[str] = None):
"""Initialize the descriptor."""
self.func = self.__wrapped__ = func

if doc is None:
doc = func.__doc__
self.__doc__ = doc

def __get__(self, obj, objtype=None):
def __get__(
self, obj: Optional[Any], objtype: Optional[Any] = None
) -> Any:
"""Implement descriptor getter.
Calculate the property's value and then store it in the
Expand All @@ -38,6 +41,6 @@ def __get__(self, obj, objtype=None):
value = obj.__dict__[self.func.__name__] = self.func(obj)
return value

def __repr__(self):
def __repr__(self) -> str:
"""Return repr(self)."""
return "<%s %s>" % (self.__class__.__name__, self.func)

0 comments on commit 31b441f

Please sign in to comment.