Skip to content

gh-134537: Clarify context manager reuse in ContextDecorator - #159848

Open
limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-134537-contextdecorator-reuse-docs
Open

limadog9 wants to merge 1 commit into
python:mainfrom
limadog9:gh-134537-contextdecorator-reuse-docs

Conversation

@limadog9

@limadog9 limadog9 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Correct the ContextDecorator equivalence example to reuse one context manager instance across calls. The previous example constructed a new instance inside the function, which can behave differently for stateful managers.

Clarify the requirements for recursive and concurrent calls, and distinguish the per-call recreation provided by contextmanager().

Fixes #134537.

Validation:

  • Verified shared instance identity across sequential and recursive decorated calls, and distinct contexts for a generator-based decorator, on the current free-threaded debug build.
  • Full HTML documentation build with warnings treated as errors.
  • Sphinx lint and patchcheck.

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35258702 | 📁 Comparing 26d52a9 against main (6044c62)

  🔍 Preview build  

1 file changed
± library/contextlib.html

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.

ContextDecorator documentation is unclear.

1 participant