Skip to content

Commit dcae8f1

Browse files
committed
gh-150076: Document the public attributes of warnings.deprecated
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.
1 parent 1736526 commit dcae8f1

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

Doc/library/warnings.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ Available Functions
566566
and calls to :func:`simplefilter`.
567567

568568

569-
.. decorator:: deprecated(msg, *, category=DeprecationWarning, stacklevel=1)
569+
.. decorator:: deprecated(message, *, category=DeprecationWarning, stacklevel=1)
570570

571571
Decorator to indicate that a class, function or overload is deprecated.
572572

@@ -612,6 +612,18 @@ Available Functions
612612
for the attribute to exist on the overload as returned by
613613
:func:`typing.get_overloads`.
614614

615+
``deprecated`` is implemented as a class, so applying it (for example,
616+
``deprecated("Use B instead")``) returns an instance that acts as the
617+
decorator. The arguments passed to it are available as attributes of the
618+
same names on that instance:
619+
620+
* ``message``: the deprecation message (a :class:`str`; a
621+
:exc:`TypeError` is raised if it is not).
622+
* ``category``: the warning category, or ``None`` if no runtime warning
623+
should be emitted.
624+
* ``stacklevel``: the number of stack frames to skip when emitting the
625+
warning (an :class:`int`).
626+
615627
.. versionadded:: 3.13
616628
See :pep:`702`.
617629

0 commit comments

Comments
 (0)