Python Glossary Русский

all Python 3Exceptionsexception

DeprecationWarning

built-in exceptions

Use of a deprecated feature, aimed at developers.

Syntax

raise DeprecationWarning

It is a Warning subclass, not an error: you almost never raise or catch it — a library emits it through warnings.warn() and execution continues. By default CPython shows DeprecationWarning only for code triggered in __main__, so warnings coming from deep inside a third-party package stay invisible until you run with -W default or python -X dev. The right response is not to silence it but to migrate the call while the old API still works.

Examples

try:
    raise DeprecationWarning
except DeprecationWarning as e:
    print(type(e).__name__)   # → DeprecationWarning

See also

Open in the full glossarydocs.python.orgReport an inaccuracy