Plan Deprecation and Removal Migrations
Core idea
A deprecation announces a discouraged API that may later change or disappear. PEP 387 describes compatibility policy, not a promise that every deprecated API disappears on a fixed date. Consult the release-specific What’s New and library notes for the alternative, affected versions and removal status. Python 3.13 removed modules such as audioop under PEP 594.
import warningsdef old_total(n): warnings.warn('use total', DeprecationWarning, stacklevel=2) return n + 1with warnings.catch_warnings(): warnings.simplefilter('error', DeprecationWarning) try: old_total(2) except DeprecationWarning: print('migration required')This synthetic legacy API lets a test expose a deprecated call before a removal.
Expected output:
migration requiredVerify the replacement contract
def total(n): return n + 1print([total(n) for n in (0, 2, -1)])Check observable behavior instead of merely suppressing warnings.
Expected output:
[1, 3, 0]Common mistake
Absence of a warning is not evidence of indefinite support: filters may hide it. A soft deprecation is also different from a scheduled removal.
Practice
Read the 3.13 removed-modules section; inventory uses of one removed module, identify a maintained alternative, and specify regression cases before replacing it.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Deprecations and removals
Check your understanding of deprecations and removals.
What is printed?
import warningswith warnings.catch_warnings(record=True) as found: warnings.simplefilter('always') warnings.warn('old', DeprecationWarning)print(len(found))What is printed?
def replacement(x): return x*2print(replacement(3))Where should removal status be confirmed?
Why run deprecation-sensitive tests?