On this page
warnings.deprecated
Prev: warnings.catch_warnings | Up: warnings | Next: warnings.filterwarnings
Rel: warnings.catch_warnings, warnings.filterwarnings, warnings.formatwarning, warnings.resetwarnings
Ref: docs.python.org — warnings.deprecated
Tags: #public #python3 #stdlib #warnings
Import
import warnings
from warnings import deprecated
Signature & Overview
warnings.deprecated(message: str, /, *, category: type[Warning] | None = <class 'DeprecationWarning'>, stacklevel: int = 1) -> None
Indicate that a class, function or overload is deprecated.
Usage
import warnings
# Python 3.13+ (PEP 702): marks a function/class deprecated for both runtime and type checkers
if hasattr(warnings, 'deprecated'):
@warnings.deprecated('Use new_fn() instead')
def old_fn(): return 1
assert old_fn() == 1
Gotchas
- Requires Python 3.13+: Replaces manual
warnings.warn(..., DeprecationWarning)boilerplate.
REPL Inspect
from warnings import deprecated
help(deprecated)
Linked from
- tuts/python3/stdlib_module/warnings
- tuts/python3/stdlib_module/warnings/catch_warnings
- tuts/python3/stdlib_module/warnings/filterwarnings
- tuts/python3/stdlib_module/warnings/formatwarning
- tuts/python3/stdlib_module/warnings/resetwarnings
- tuts/python3/stdlib_module/warnings/showwarning
- tuts/python3/stdlib_module/warnings/simplefilter
- tuts/python3/stdlib_module/warnings/warn
- tuts/python3/stdlib_module/warnings/warn_explicit
Related notes
- tuts/python3/stdlib_module/warnings/catch_warnings Linked here; links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/filterwarnings Linked here; links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/formatwarning Linked here; links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/resetwarnings Linked here; links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/warnings/showwarning links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/simplefilter links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/warn links to this page; shared tags: #stdlib, #warnings
- tuts/python3/stdlib_module/warnings/warn_explicit links to this page; shared tags: #stdlib, #warnings
- tuts/c/stdlib shared tags: #stdlib