Deprecated feature used
Production Risk
Low now, high later — deprecated features are removed in future versions.
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.
- 1Calling a function or using a parameter that is marked deprecated in Python or a library
- 2Using a module that has been superseded
Using a deprecated distutils function.
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
# 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.
import warnings
warnings.warn("old_api is deprecated", DeprecationWarning, stacklevel=2)import warnings
with warnings.catch_warnings():
warnings.simplefilter("error", DeprecationWarning)
call_library() # DeprecationWarning becomes error# python -W default script.py to see all warnings # Then update to the recommended replacement
✕ Suppress DeprecationWarnings in tests
They signal upcoming breaking changes; suppressing them means being caught off-guard when the feature is removed.
Python Docs — Built-in Exceptions
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev