Member-only story
Python 3.10 is Released. Know What’s New and If It’s Worth the Switch
Improvements in type annotation, structural pattern matching, better error messages, and performance

Python 3.10 was released on the 4th of October 2021 according to PEP 619. Let’s see what’s in store for us.
Type Annotations
I absolutely love type annotations. Since Python 3.6, they are super useful. If you don’t use them already, I highly recommend you to read my introduction.
Python 3.10 has improved them again! Let’s see how
TypeGuards: Conditional Type Narrowing
PEP 647 introduces a new TypeGuard annotation. It’s backported via typing_extensions.
from typing_extensions import TypeGuard # Before Python 3.10
from typing import TypeGuard # With Python 3.10
Without TypeGuards, you could not find that there is an issue with this:
But with the TypeGuard, you can see:
typeguard.py:17: error: TypedDict "User" has no key "x"Found 1 error in 1 file (checked 1 source file)
Neat! Now you can get rid of a couple of cast
andassert
calls or comments like # type: ignore
.
Syntactic Sugar: Allow writing union types as X | Y ✨
Readability counts. The documentation is a lot of the reason why I love type annotations so much. PEP 604 allows you to use a more concise syntax that is easier to read: