Skip to content
Merged
Changes from all 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
11 changes: 7 additions & 4 deletions pytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import sys
import logging
from typing import (
Any, Callable, Dict, Hashable, Iterable,
cast, Any, Callable, Dict, Hashable, Iterable,
List, Optional, Set, Tuple, TypeVar)
import builtins

Expand Down Expand Up @@ -678,7 +678,7 @@ class _HasKwargs:
pass


def memoize_on_first_arg(function, cache_dict_name=None):
def memoize_on_first_arg(function: F, cache_dict_name=None) -> F:
"""Like :func:`memoize_method`, but for functions that take the object
in which do memoization information is stored as first argument.

Expand Down Expand Up @@ -716,9 +716,12 @@ def clear_cache(obj):

from functools import update_wrapper
new_wrapper = update_wrapper(wrapper, function)
new_wrapper.clear_cache = clear_cache

return new_wrapper
# type-ignore because mypy has a point here, stuffing random attributes
# into the function's dict is moderately sketchy.
new_wrapper.clear_cache = clear_cache # type: ignore[attr-defined]

return cast(F, new_wrapper)


def memoize_method(method: F) -> F:
Expand Down