Development

Python 3.8 end of life coming soon

Radek Lát

Development

Python 3.8 will/has reached its end of life by the end of this month. Soon, you will be forced to upgrade as tools and libraries gradually start removing its support. If you are considering upgrading to the latest Python version, take it. But especially library maintainers don’t have that luxury and still have to keep 3.9 support around. It’s been a while since all the „What’s new in Python 3.9″ articles came out. So here’s a farewell of what’s going away and hello to what you can use instead.


Before we go into the details of what’s changing, I recommend trying a pyupgrade tool first to see what Python 3.9+ changes can be done for you automatically.


typing Generic (PEP 585)

While typing generics such as list […] and dict […, …] have been possible since Python 3.7 thanks to from __future__ import annotations, there might be still places in the code base that use the old typing. List / typing. Dict generics. After Python 3.8, these can officially go. What can be replaced?

typing. Tuple -> tuple
typing. List -> list
typing. Dict -> dict
typing. Set -> set
typing. FrozenSet -> frozenset
typing. Type -> type
typing. ContextManager -> contextlib. AbstractContextManager
typing. AsyncContextManager -> contextlib. AbstractAsyncContextManager
typing. Pattern -> re. Pattern
typing. Match -> re. Match
There are also other generics that are completely new.


Operator for merging dicts (PEP 884)


{**d1, **d2} -> d1 – d2

d1. update(d2) -> d1 |= d2


New String Methods to Remove Prefixes and Suffixes (PEP 616)

You may have various local or back-ported implementations that can now be replaced with built-in ones:

removeprefix(string, prefix) -> string.removeprefix(prefix)

removesuffix(string, prefix) -> string.removesuffix(prefix)


For more details on IANA Time Zone Database in the Standard Library (PEP 615) or Flexible function and variable annotations (PEP 593), please go directly to Rad´s Blog. You can leave him a comment there as well. Good luck with the 3.9 upgrade.

Author

Radek Lát

Development

@radeklat

Rad is an aspiring tech lead in Heureka. He loves everything Python, DevEx and is always a fan of a nice spreadsheet. You can meet him in person in PyCons and Europythons, where he likes to connect with the community and get fresh ideas. Outside of work, he likes to keep fit, tinker with environmental sensors and home automation, travel and take photos.

<We are social too/>

Interested in our work, technology, team, or anything else?
Contact our CTO Lukáš Putna.

lukas.putna@heureka.cz