diff options
author | Jelle Zijlstra <jelle.zijlstra@gmail.com> | 2023-11-29 17:38:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-29 17:38:29 (GMT) |
commit | d4a6229afe10d7e5a9a59bf9472f36d7698988db (patch) | |
tree | 4fab807bd51c3eab369b5dac8a3df0987b1f1647 /Doc/library/warnings.rst | |
parent | 403886942376210662610627b01fea6acd77d331 (diff) | |
download | cpython-d4a6229afe10d7e5a9a59bf9472f36d7698988db.zip cpython-d4a6229afe10d7e5a9a59bf9472f36d7698988db.tar.gz cpython-d4a6229afe10d7e5a9a59bf9472f36d7698988db.tar.bz2 |
gh-104003: Implement PEP 702 (#104004)
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Diffstat (limited to 'Doc/library/warnings.rst')
-rw-r--r-- | Doc/library/warnings.rst | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst index 884de08..a9c4697 100644 --- a/Doc/library/warnings.rst +++ b/Doc/library/warnings.rst @@ -522,6 +522,56 @@ Available Functions and calls to :func:`simplefilter`. +.. decorator:: deprecated(msg, *, category=DeprecationWarning, stacklevel=1) + + Decorator to indicate that a class, function or overload is deprecated. + + When this decorator is applied to an object, + deprecation warnings may be emitted at runtime when the object is used. + :term:`static type checkers <static type checker>` + will also generate a diagnostic on usage of the deprecated object. + + Usage:: + + from warnings import deprecated + from typing import overload + + @deprecated("Use B instead") + class A: + pass + + @deprecated("Use g instead") + def f(): + pass + + @overload + @deprecated("int support is deprecated") + def g(x: int) -> int: ... + @overload + def g(x: str) -> int: ... + + The warning specified by *category* will be emitted at runtime + on use of deprecated objects. For functions, that happens on calls; + for classes, on instantiation and on creation of subclasses. + If the *category* is ``None``, no warning is emitted at runtime. + The *stacklevel* determines where the + warning is emitted. If it is ``1`` (the default), the warning + is emitted at the direct caller of the deprecated object; if it + is higher, it is emitted further up the stack. + Static type checker behavior is not affected by the *category* + and *stacklevel* arguments. + + The deprecation message passed to the decorator is saved in the + ``__deprecated__`` attribute on the decorated object. + If applied to an overload, the decorator + must be after the :func:`@overload <typing.overload>` decorator + for the attribute to exist on the overload as returned by + :func:`typing.get_overloads`. + + .. versionadded:: 3.13 + See :pep:`702`. + + Available Context Managers -------------------------- |