[Python-checkins] bpo-45701: Improve documentation for *typed* parameter (GH-29498) (GH-29509)
ambv
webhook-mailer at python.org
Thu Nov 18 11:12:17 EST 2021
https://github.com/python/cpython/commit/0df5d31ac7b32d3b948952c834783cd357fa3e22
commit: 0df5d31ac7b32d3b948952c834783cd357fa3e22
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: ambv <lukasz at langa.pl>
date: 2021-11-18T17:12:07+01:00
summary:
bpo-45701: Improve documentation for *typed* parameter (GH-29498) (GH-29509)
(cherry picked from commit 912a4ccc3a523e2990cc501393adfc661614c73a)
Co-authored-by: Raymond Hettinger <rhettinger at users.noreply.github.com>
files:
M Doc/library/functools.rst
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index a01b17287878c..c78818bfab1a5 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -160,10 +160,16 @@ The :mod:`functools` module defines the following functions:
grow without bound.
If *typed* is set to true, function arguments of different types will be
- cached separately. For example, ``f(3)`` and ``f(3.0)`` will always be
- treated as distinct calls with distinct results. If *typed* is false,
- the implementation will usually but not always regard them as equivalent
- calls and only cache a single result.
+ cached separately. If *typed* is false, the implementation will usually
+ regard them as equivalent calls and only cache a single result. (Some
+ types such as *str* and *int* may be cached separately even when *typed*
+ is false.)
+
+ Note, type specificity applies only to the function's immediate arguments
+ rather than their contents. The scalar arguments, ``Decimal(42)`` and
+ ``Fraction(42)`` are be treated as distinct calls with distinct results.
+ In contrast, the tuple arguments ``('answer', Decimal(42))`` and
+ ``('answer', Fraction(42))`` are treated as equivalent.
The wrapped function is instrumented with a :func:`cache_parameters`
function that returns a new :class:`dict` showing the values for *maxsize*
More information about the Python-checkins
mailing list