Built-in Exceptions
DeprecationWarning — exception class
Indicates a deprecated feature for Python developers. Default filters typically hide it outside __main__; tests should enable it explicitly rather than assume users see it. The example explicitly promotes this warning category to an exception to make the result independent of default filters. Catch DeprecationWarning when this category is the recovery boundary; do not rely on the exact human-readable message.
Formal Syntax & Structure
python syntaxpython
DeprecationWarningReturn Value
type
The class object DeprecationWarning; this reference documents the class identity, not a universal constructor signature.
Working Example
Example Snippetpython
import warningstry: with warnings.catch_warnings(): warnings.simplefilter("error", DeprecationWarning) warnings.warn("demo", DeprecationWarning)except DeprecationWarning as error: print(type(error).__name__)