Skip to content

gh-150076: Fix the documented signature of warnings.deprecated#153879

Merged
JelleZijlstra merged 7 commits into
python:mainfrom
fedonman:fix-gh-150076-warnings-deprecated-api
Jul 22, 2026
Merged

gh-150076: Fix the documented signature of warnings.deprecated#153879
JelleZijlstra merged 7 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 documented signature for warnings.deprecated used msg as the first parameter, but the implementation names it message and it is positional-only. This updates the documented signature to match.

An earlier version of this PR also documented that deprecated is a class whose instances expose message, category and stacklevel attributes. As discussed in review, that is not guaranteed by PEP 702 or the typing spec, so documenting it would turn an implementation detail into a permanent API commitment. I dropped that part. Whether those attributes should become guaranteed public API is a separate question that belongs in the typing spec.

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

@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.

@fedonman

Copy link
Copy Markdown
Contributor Author

@zware part of EuroPython sprint.

…ic API

The paragraph described deprecated as a class exposing its constructor
arguments as message, category and stacklevel attributes. Neither PEP 702
nor the typing spec guarantees this, so documenting it would turn an
implementation detail into a permanent API commitment. Drop it and keep
only the msg -> message signature fix, which matches the actual
positional-only parameter.
@fedonman

fedonman commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

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.

Thanks, I looked into it. You're right that PEP 702 only guarantees the deprecated attribute on the decorated object. It doesn't require deprecated to be a class and doesn't mention the message, category or stacklevel attributes, and the typing spec even says the runtime category/stacklevel behaviour is out of scope. So documenting those attributes would turn an implementation detail into a permanent API commitment, which isn't what this PR should do.

I've dropped that paragraph. The PR is now just the msg -> message signature fix, so the documented parameter matches the actual positional-only parameter in the implementation. That part is a straightforward correctness fix with no API implications, so I think it's good to merge as is.

The separate question of whether the class and its attributes should become guaranteed public API (typeshed and Pydantic already rely on them) really belongs in the typing spec, so I'm happy to take that up there rather than hold this fix.

@picnixz

picnixz commented Jul 19, 2026

Copy link
Copy Markdown
Member

Please update the PR title and description then. I don't think we want to document the implementation being a class, but we can do it in a separate PR. But we can ask @JelleZijlstra

@fedonman fedonman changed the title gh-150076: Document the public attributes of warnings.deprecated gh-150076: Fix the documented signature of warnings.deprecated Jul 19, 2026
@fedonman

Copy link
Copy Markdown
Contributor Author

done

Comment thread Doc/library/warnings.rst Outdated
@fedonman
fedonman requested a review from JelleZijlstra July 21, 2026 13:30
@JelleZijlstra JelleZijlstra added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 22, 2026
@JelleZijlstra
JelleZijlstra merged commit 56ad3bc into python:main Jul 22, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in Sprint Jul 22, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in Docs PRs Jul 22, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @fedonman for the PR, and @JelleZijlstra for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 22, 2026

Copy link
Copy Markdown

GH-154487 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 22, 2026
@bedevere-app

bedevere-app Bot commented Jul 22, 2026

Copy link
Copy Markdown

GH-154488 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 22, 2026
@bedevere-app

bedevere-app Bot commented Jul 22, 2026

Copy link
Copy Markdown

GH-154489 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 22, 2026
JelleZijlstra added a commit that referenced this pull request Jul 22, 2026
…GH-153879) (#154489)

gh-150076: Fix the documented signature of warnings.deprecated (GH-153879)
(cherry picked from commit 56ad3bc)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit that referenced this pull request Jul 22, 2026
…GH-153879) (#154488)

gh-150076: Fix the documented signature of warnings.deprecated (GH-153879)
(cherry picked from commit 56ad3bc)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra added a commit that referenced this pull request Jul 22, 2026
…GH-153879) (#154487)

gh-150076: Fix the documented signature of warnings.deprecated (GH-153879)
(cherry picked from commit 56ad3bc)

Co-authored-by: Vyron Vasileiadis <hi@fedonman.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@fedonman
fedonman deleted the fix-gh-150076-warnings-deprecated-api branch July 22, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news sprint

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants