On this page
  1. warnings.deprecated
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from warnings import deprecated
help(deprecated)

Linked from

Related notes