Skip to content

Commit 128ea42

Browse files
committed
Move the docstring for cached_method to public func
In order for `help(functools.cached_method)` to show the docstring, it needs to be attached to the public interface, not the implementation. This docstring was "misplaced" in the course of refactors to this code during review.
1 parent a7f206c commit 128ea42

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

Lib/functools.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,18 +1146,6 @@ def wrapped(*args, **kwargs):
11461146

11471147

11481148
class _cached_method:
1149-
"""
1150-
A caching decorator for use on instance methods.
1151-
1152-
Using cache or lru_cache on methods is problematic because the instance is put into
1153-
the cache and cannot be garbage collected until the cache is cleared. This decorator
1154-
uses a cache based on `id(self)` and a weakref to clear cache entries.
1155-
1156-
The instance must be weak-referencable.
1157-
1158-
By default, this provides an infinite sized cache similar to functools.cache. Use
1159-
*maxsize* and *typed* to set these attributes of the underlying LRU cache.
1160-
"""
11611149
def __init__(self, func, /, maxsize=None, typed=False):
11621150
self._function_table = {}
11631151

@@ -1197,6 +1185,18 @@ def _get_or_create_cached_func(self, instance):
11971185

11981186

11991187
def cached_method(func=None, /, maxsize=None, typed=False):
1188+
"""
1189+
A caching decorator for use on instance methods.
1190+
1191+
Using cache or lru_cache on methods is problematic because the instance is put into
1192+
the cache and cannot be garbage collected until the cache is cleared. This decorator
1193+
uses a cache based on `id(self)` and a weakref to clear cache entries.
1194+
1195+
The instance must be weak-referencable.
1196+
1197+
By default, this provides an infinite sized cache similar to functools.cache. Use
1198+
*maxsize* and *typed* to set these attributes of the underlying LRU cache.
1199+
"""
12001200
if maxsize is not None and not isinstance(maxsize, int) and not callable(maxsize):
12011201
raise TypeError(
12021202
'Expected maxsize to be an integer, a callable, or None')

0 commit comments

Comments
 (0)