Deprecations via warnings don't work for Python libraries

sethmlarson.dev

58 points by scolby33 3 days ago


traverseda - a day ago

Wait, does urlib not use semvar? Don't remove APIs on minor releases people. A major release doesn't have to be a problem or a major redesign, you can do major release 400 for all I care, just don't break things on minor releases.

Lots of things not using semvar that I always just assumed did.

jakub_g - a day ago

Fixing deprecations is unfortunately the lowest prio of any kind of work for majority of the projects. Part of the problem is probably lack of pressure to do so it if the timeline is unclear. What if this is actually never removed? Why going through the pain?

IMO telling "we deprecate now and let's see when we remove it" is counterproductive.

A better way: deprecate now and tell "in 12 (or 24?) months this WILL be removed".

After 12/24 months, cut a new semver-major release. People notice the semver-major through the dependency management tools at some point, an maybe they have a look at changelog.

If they don't, at some point they may want to use a new feature, and finally be incentivised to update.

If there's no incentive other than "do the right thing", it never gets done.

Having said that, I think LLMs are really going to help with chores like this, if e.g. deprecations and migration steps are well documented.

Alternative option: create a codemod CLI that fixes deprecations for the users, doing the right thing automatically. If migration is painless and quick, it's more likely people will do it.

eddythompson80 - a day ago

Deprecations in all forms are always a shitshow. There isn’t a particular pattern that “just works”. Anybody that tells you about one, best case scenario, it just worked for them because of their consumer/user not because of the method itself.

The best I have seen is a heavy handed in-editor strike through with warnings (assuming the code is actively being worked on) and even then it’s at best a 50/50 thing.

50% of the developers would feel that using an API with a strike through in the editor is wrong. And the other 50% will just say “I dunno, I copied it from there. What’s wrong with it??”

theamk - 3 days ago

Deprecations via warnings don't reliably work anywhere, in general.

If you are a good developer, you'll have extensive unit test coverage and CI. You never see the unit test output (unless they fail) - so warnings go unnoticed.

If you are a bad developer, you have no idea what you are doing and you ignore all warnings unless program crashes.

akie - 21 hours ago

Start adding a 500ms delay to every invocation of a deprecated function. Incentives work!

hiq - a day ago

Wild (and I guess most of the time bad) idea: on top of the warnings, introduce a `sleep` in the deprecated functions. At every version, increase the sleep.

Has this ever been considered?

The problem with warnings is that they're not really observable: few people actually read these logs, most of the time. Making the deprecation observable means annoying the library users. The question is then: what's the smallest annoyance we can come up with, so that they still have a look?

Revisional_Sin - a day ago

> Maybe the answer is to do away with advance notice and adopt SemVer with many major versions

Yes.

Incipient - 13 hours ago

I'm very confused on the debate of semver here - the fundamental principle seems very simple, and important.

"give me all updates to my core version that's still compatible"

Semver simply puts a 'protocol' to this - define your major version and off you go.

While in practice you could go and search for each and every library you use to check when/how they do breaking versions, but semver just allows matching a single number across the board - it makes it more consistent and error proof.

skeledrew - 13 hours ago

Instead of reverting the updates to appease those who've been ignoring the warnings, a way forward could be to gate the old API behind an environment variable, with a name like "TEMPORARILY_REENABLE_DEPRECATED_APIS". And maybe put an expiry on the variable so it resets occasionally. Otherwise the project just becomes mired and stagnant.

tgsovlerkhgsel - 20 hours ago

Deprecations don't work. Don't deprecate stuff without a really really good reason. The new API being cleaner is not a good reason. There are very few good reasons.

If you deprecate something in a popular library, you're forcing millions of people to do work. Waste time that could be used for something better, possibly at a time of your choice, not theirs. It was emitting warnings for 3 years... so you think everyone should have to rewrite their software every 3 years?

Especially for something like this. Only document it in a footnote, mark it as deprecated, etc - but don't remove the alias.

Don't break stuff, unless, to quote a famous work, you think your users are scum. Do you think your users are scum? Why do you hate your users?

hartator - a day ago

I think they are misreading the situation.

The devil is in the details. It seems `getHeaders` v. `headers` is non-security, non-performance related issue. Why people should spend time fixing these?

plantain - 21 hours ago

# Deprecated APIs resp.getheader("Content-Length")

# Recommended APIs resp.headers.get("Content-Length")

Why inflict this change on tens of millions of users? It's such a nonsense tiny busywork change. Let sleeping dogs lie.

Hackbraten - a day ago

A deprecation warning is not actionable for typical end users. Why don't more warnings include calls to action?

Instead of a warning that says, "The get_widget method in libfoo is deprecated and will be removed by November 30", the warning could say:

"This app uses the deprecated get_widget method. Please report this bug to the app developer. Ask them to fix this issue so you can continue using this app after November 30."

jeffrallen - 21 hours ago

I prefer Go's solution to this problem. Just don't deprecate stuff. And to make that possible, slow down and design stuff you will be willing to support forever.

superkuh - a day ago

>We ended up adding the APIs back and creating a hurried release to fix the issue.

So it was entirely possible to keep the software working with these. Why change/remove them in the first place? Is the benefit of of the new abstraction greater than the downside of requiring everyone using the software to re-write theirs?

bigstrat2003 - 19 hours ago

Honestly, I think that the author already found (and rejected the solution):

> I could ask for more Python developers to run with warnings enabled, but solutions in the form of “if only we could all just” are a folly.

I get where he's coming from. But the facts are: the language provides a tool to warn users, the library is using that tool, and users are choosing to turn that tool off. That's fine, but then they don't get to complain when stuff breaks without warning. It is the user's responsibility at that point, not the library maintainers'.

shadowgovt - a day ago

The secret trick I've used on rare occasion, but when necessary, is the "ten second rule."

Users don't notice a deprecation warning. But they might notice adding a "time.sleep(10)" immediately at the top of the function. And that gives them one last grace period to change out their software before it breaks-breaks.