Skip to content

Docs: Qualify the lru_cache scalar example with typed=True - #158424

Open
esadomer wants to merge 1 commit into
python:mainfrom
esadomer:b01-p002-lru-cache-typed-example
Open

esadomer wants to merge 1 commit into
python:mainfrom
esadomer:b01-p002-lru-cache-typed-example

Conversation

@esadomer

Copy link
Copy Markdown
Contributor

Summary

State that the lru_cache example distinguishing Decimal(42) from Fraction(42) uses typed=True. With the default typed=False, these scalar arguments share a cache entry. Tuple-contained values share an entry in either mode, as the surrounding explanation intends.

from decimal import Decimal
from fractions import Fraction
from functools import lru_cache

for typed in (False, True):
    cached = lru_cache(typed=typed)(repr)
    cached(Decimal(42))
    cached(Fraction(42))
    print(typed, cached.cache_info())

This gives one hit and one miss for False, and zero hits and two misses for True. The existing allowance for implementation-dependent caching with typed=False is preserved.

Validation

  • Built CPython 3.16.0a0 from the checkout with PCbuild\build.bat -p x64 -d -M on Windows 10 x64 (MSVC 19.30).
  • PCbuild\amd64\python_d.exe -m test test_functools: SUCCESS (run=339, skipped=0).
  • Verified the examples and boundary cases with the same debug interpreter.
  • python -m sphinx -W --keep-going -j 1 -b html -d build/doctrees . build/html from Doc: incremental HTML build passed with Sphinx 8.2.3. The clean baseline build reported an existing duplicate customization label in using/windows.rst and reference/datamodel.rst.
  • python -m sphinxlint Doc/library/functools.rst, PCbuild\amd64\python_d.exe Tools\patchcheck\patchcheck.py, and git diff --check: passed.

This changes documentation only. No NEWS entry is needed. The full interpreter test suite was not run.

@bedevere-app bedevere-app Bot added docs Documentation in the Doc dir skip news labels Sep 29, 2026
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34831703 | 📁 Comparing 4260736 against main (84d4601)

  🔍 Preview build  

1 file changed
± library/functools.html

@esadomer
esadomer marked this pull request as ready for review September 29, 2026 15:37
@rhettinger rhettinger self-assigned this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants