From b59289f508f2917b2d9f6f566644c06532a1e4a5 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 10 Feb 2023 15:37:30 -0800 Subject: [PATCH 1/2] gh-101815: fix functools.cached_property key sharing doc warnings --- Doc/library/functools.rst | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 2f0a9bd8be8815..76fcfbd35e481c 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -86,20 +86,17 @@ The :mod:`functools` module defines the following functions: The cached value can be cleared by deleting the attribute. This allows the *cached_property* method to run again. - Note, this decorator interferes with the operation of :pep:`412` - key-sharing dictionaries. This means that instance dictionaries - can take more space than usual. - - Also, this decorator requires that the ``__dict__`` attribute on each instance - be a mutable mapping. This means it will not work with some types, such as + This decorator requires that the ``__dict__`` attribute on each instance be a + mutable mapping. This means it will not work with some types, such as metaclasses (since the ``__dict__`` attributes on type instances are read-only proxies for the class namespace), and those that specify - ``__slots__`` without including ``__dict__`` as one of the defined slots - (as such classes don't provide a ``__dict__`` attribute at all). + ``__slots__`` without including ``__dict__`` as one of the defined slots (as + such classes don't provide a ``__dict__`` attribute at all). Also, accessing + ``__dict__`` can cause object instances to use slightly more memory. - If a mutable mapping is not available or if space-efficient key sharing - is desired, an effect similar to :func:`cached_property` can be achieved - by a stacking :func:`property` on top of :func:`cache`:: + If a mutable mapping is not available, an effect similar to + :func:`cached_property` can be achieved by a stacking :func:`property` on top + of :func:`cache`:: class DataSet: def __init__(self, sequence_of_numbers): From 18c99a85a92736977ee683903593fbb7ae1774be Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 10 Feb 2023 16:02:11 -0800 Subject: [PATCH 2/2] remove a pre-existing typo also --- Doc/library/functools.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst index 76fcfbd35e481c..cbddb3eca2be8f 100644 --- a/Doc/library/functools.rst +++ b/Doc/library/functools.rst @@ -95,7 +95,7 @@ The :mod:`functools` module defines the following functions: ``__dict__`` can cause object instances to use slightly more memory. If a mutable mapping is not available, an effect similar to - :func:`cached_property` can be achieved by a stacking :func:`property` on top + :func:`cached_property` can be achieved by stacking :func:`property` on top of :func:`cache`:: class DataSet: