mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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>
This commit is contained in:
parent
4038869423
commit
d4a6229afe
5 changed files with 473 additions and 2 deletions
|
|
@ -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
|
||||
--------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue