Remix.run Logo
Hackbraten 7 months ago

> yet another Python thing I'd have to try to keep in my mind despite it being months since I used them last.

Typing hints are also a moving target: they have changed, sometimes significantly, on every minor Python release since they came to be.

The `Optional` type came and went (being replaced by the new Union syntax.) Type classes are usually born in the `typing` module, then some of them get moved to `collections`, `abc`, or `collections.abc`. Some types have even been moved several times. `TypeAlias` came and went (replaced by `type`). `List` became `list`. `Tuple` became `tuple`. Forward declarations require a workaround by using string literals. But in Python 3.14, they no longer do, and the workaround will become deprecated.

I'm an evangelist for static type checking, and I never write a Python function signature without complete typing annotations. I also think that typing annotations in Python are evolving in a good way. However, for long-lived Python scripts, I highly recommend that developers are aware of, and factor in, the effort necessary to keep up with the evolution of static typing across Python versions. That effort spent on migrating is going to come on top of the mental load that typing hints already add to your plate.

maleldil 7 months ago | parent | next [-]

The old stuff never stopped working, though. You can still use Optional, Union, TypeAlias, and import collection protocols from typing. You don't have to migrate if you don't want to. They're not even deprecated.

Hackbraten 7 months ago | parent | next [-]

I encourage you to open the `typing` documentation [0] and search for the word `deprecated`.

Spoiler alert: the search result will be three-figure.

Some of the results are already scheduled for removal.

[0]: https://docs.python.org/3/library/typing.html

maleldil 7 months ago | parent [-]

This is the relevant bit:

> The redundant types are deprecated as of Python 3.9. However, while the aliases may be removed at some point, removal of these aliases is not currently planned. As such, no deprecation warnings are currently issued by the interpreter for these aliases.

The idea is that new code shouldn't use them, but they work perfectly fine and will keep working in the near future. Even if they decide to remove these at some point, you're looking at several years before it actually happens, and you'll have plenty of time to migrate.

As it stands, you can use them to your heart's content without issues.

Hackbraten 7 months ago | parent [-]

Your quote only refers to a small part of the deprecations, i.e. deprecated type aliases. Deprecations that are not in that group do cause warnings, and some of them are already scheduled for removal.

Your quote also conveniently left out the following paragraph:

> The aliases are guaranteed to remain in the typing module without deprecation warnings until at least Python 3.14.

Python 3.14 is less than a year away.

> Even if they decide to remove these at some point, you're looking at several years before it actually happens, and you'll have plenty of time to migrate.

I agree. I still think it adds to the pile of chores, especially for people who are on the fence anyway as to whether type annotations are worth the additional mental load to them.

aragilar 7 months ago | parent | prev [-]

I've seen multiple major projects (such a sphinx) break on newer versions of Python due to changes in typing. Typing should make the code more robust, not less.

maleldil 7 months ago | parent [-]

Do you have any examples? What kind of changes were there?

adammarples 7 months ago | parent | prev | next [-]

None of those things came and went, they came but did not go. They're all still here, even in the 3.14 beta.

hopfenspergerj 7 months ago | parent | prev [-]

Ruff can automatically upgrade all of the issues you mentioned to match your target minimum python version.

Hackbraten 7 months ago | parent [-]

Good to know, thanks!