DeprecationWarning
PythonWARNINGCommonWarningHIGH confidence

Deprecated feature used

Production Risk

Low now, high later — deprecated features are removed in future versions.

What this means

Issued when code uses a deprecated feature or API. DeprecationWarnings are silenced by default in non-development mode but appear when running tests or with -Wd.

Why it happens
  1. 1Calling a function or using a parameter that is marked deprecated in Python or a library
  2. 2Using a module that has been superseded
How to reproduce

Using a deprecated distutils function.

trigger — this will error
trigger — this will error
import warnings
warnings.warn("use new_api() instead", DeprecationWarning, stacklevel=2)

expected output

DeprecationWarning: use new_api() instead

Fix

Migrate to the recommended replacement

WHEN When a DeprecationWarning is raised

Migrate to the recommended replacement
# Run with warnings enabled to see them:
python -W default script.py
# or
python -W error::DeprecationWarning script.py  # Treat as error

# Then fix by using the recommended replacement shown in the warning

Why this works

-W error::DeprecationWarning turns warnings into errors during testing, ensuring deprecations are not ignored.

Code examples
Triggerpython
import warnings
warnings.warn("old_api is deprecated", DeprecationWarning, stacklevel=2)
Handle in test suitepython
import warnings
with warnings.catch_warnings():
    warnings.simplefilter("error", DeprecationWarning)
    call_library()  # DeprecationWarning becomes error
Avoid by migrating to new APIpython
# python -W default script.py to see all warnings
# Then update to the recommended replacement
What not to do

Suppress DeprecationWarnings in tests

They signal upcoming breaking changes; suppressing them means being caught off-guard when the feature is removed.

Sources
Official documentation ↗

Python Docs — Built-in Exceptions

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Python errors