Skip to content

gh-150076: Document the public attributes of warnings.deprecated#153879

Open
fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-gh-150076-warnings-deprecated-api
Open

gh-150076: Document the public attributes of warnings.deprecated#153879
fedonman wants to merge 2 commits into
python:mainfrom
fedonman:fix-gh-150076-warnings-deprecated-api

Conversation

@fedonman

@fedonman fedonman commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

The docs for warnings.deprecated only mention the __deprecated__ attribute set on the decorated object. They don't mention that deprecated is a class whose instances expose their constructor arguments as attributes with the same names (message, category and stacklevel). That is part of the public API, and downstream projects like Pydantic rely on it.

This documents those three attributes inside the existing decorator entry, using the same bullet-list style already used for the catch_warnings recorded-object attributes. It also renames the first parameter in the documented signature from msg to message, to match the implementation (where it is positional-only) and the attribute being documented.

I kept the directive as .. decorator:: instead of switching to .. class:: so the existing warnings.deprecated references in Doc/whatsnew/3.13.rst still resolve.

Checked with a nitpicky docs build (sphinx-build -n -D nitpicky=1): no new warnings.

The documentation described only the ``__deprecated__`` attribute set on
the decorated object, and did not mention that ``deprecated`` is a class
whose instances expose the constructor arguments (``message``, ``category``
and ``stacklevel``) as attributes of the same names -- a part of the API
that downstream projects rely on.

Document these attributes, and rename the first parameter in the signature
from ``msg`` to ``message`` to match the implementation and the attribute.
@read-the-docs-community

read-the-docs-community Bot commented Jul 18, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33644574 | 📁 Comparing 7fccd37 against main (16d0c89)

  🔍 Preview build  

3 files changed
± library/asyncio-task.html
± library/warnings.html
± whatsnew/changelog.html

@picnixz

picnixz commented Jul 18, 2026

Copy link
Copy Markdown
Member

Documenting this like that makes it an implementation-detail IMO. For context, can you look at the related PEP (there seems to be one) please? and check for past discussions. Exposing an implementation details opens cans of worms that we usually want to keep closed.

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