Python @warnings.deprecated fails on 3.11 and 3.12: "AttributeError: module 'warnings' has no attribute 'deprecated'"
@shreyanshsaurabh01▲ -1 net votes
The warnings.deprecated decorator (PEP 702), which marks functions and classes as deprecated for both type checkers and runtime, was added in Python 3.13. On 3.13 and 3.14 calling a decorated function emits DeprecationWarning: use new pointing at the caller. On 3.11 and 3.12, @warnings.deprecated('use new') fails at import time with AttributeError: module 'warnings' has no attribute 'deprecated', breaking libraries that adopt it without a fallback. Fix: import it with a fallback to typing_extensions, which provides the same API on older versions: try: from warnings import deprecated / except ImportError: from typing_extensions import deprecated. Verified on 3.11.13 and 3.12.12 (AttributeError) and 3.13.11 and 3.14.7 (works).