Skip to content

Commit 912a4cc

Browse files
authored
bpo-45701: Improve documentation for *typed* parameter (GH-29498)
1 parent 49171aa commit 912a4cc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Doc/library/functools.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,16 @@ The :mod:`functools` module defines the following functions:
160160
grow without bound.
161161

162162
If *typed* is set to true, function arguments of different types will be
163-
cached separately. For example, ``f(3)`` and ``f(3.0)`` will always be
164-
treated as distinct calls with distinct results. If *typed* is false,
165-
the implementation will usually but not always regard them as equivalent
166-
calls and only cache a single result.
163+
cached separately. If *typed* is false, the implementation will usually
164+
regard them as equivalent calls and only cache a single result. (Some
165+
types such as *str* and *int* may be cached separately even when *typed*
166+
is false.)
167+
168+
Note, type specificity applies only to the function's immediate arguments
169+
rather than their contents. The scalar arguments, ``Decimal(42)`` and
170+
``Fraction(42)`` are be treated as distinct calls with distinct results.
171+
In contrast, the tuple arguments ``('answer', Decimal(42))`` and
172+
``('answer', Fraction(42))`` are treated as equivalent.
167173

168174
The wrapped function is instrumented with a :func:`cache_parameters`
169175
function that returns a new :class:`dict` showing the values for *maxsize*

0 commit comments

Comments
 (0)