liveBook · Manning

DeprecationWarning

As explained in Practices of the Python Pro

A deprecation warning is a diagnostic notification that an interface, behavior, or feature is obsolete and may be removed or changed in a future version.

A DeprecationWarning tells users that an interface should no longer be used and points them toward replacement code. It helps a refactoring remain backward-compatible while consumers migrate. section 9.3.2

Warning during an API transition

When replacing book.author_for_display with book.author.for_display, emit `warnings.warn('Use book.author.for_display instead', DeprecationWarning)`. The output identifies the warning and the replacement path. section 9.3.2

Figure 9.4. Mail can be forwarded by the post office when you move to a new location.

Use forwarding as an analogy: old API calls can temporarily route users toward the new location while migration takes place. section 9.3.2

How Practices of the Python Pro covers it

How deep it goes
Defines the warning, demonstrates its Python call and output, and stops short of discussing warning internals.
Examples
Uses deprecated Book properties, an Author replacement, Python warnings.warn, and a printed migration message.
What you can do after
Apply it via Python's warnings system to guide consumers toward replacement APIs.
How it connects
Connects class extraction with composition, forwarding calls, and backward compatibility.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.