What’s new in Python 3.11

Python 3.11 is out!!!

This is one of the most exciting releases in a while, including significant speed upgrades and better error messages.

Here’s what’s new:

1. Faster CPython!

Python 3.11 is anywhere between 10-60% faster than Python 3.10, and on average it’s 25% faster.

This includes faster startup times and more efficient use of/communication with C.

Here are the individual operations that are notably faster:

2. Better error messages

Anyone who has used a language like Rust knows that Python left something to be desired when it came to error messages.

Well, now Python has error messages that highlight the specific location of the problem!

3. Grouped exceptions

We now have the introduction of the “except*” class, which allows you to have more flexible error handling.

You can create a group of exceptions that may partially match with multiple of these except* clauses.

4. Added notes on exceptions

Sometimes, when you’re catching an error, it’s helpful to leave an extra note to the user as to exactly *why* the error was raised. Many libraries (like Keras) spend a lot of time trying to enhance this.

Well, the .add_note() method now allows this!

5. A bunch of type hint stuff

There’s now support for a Self type and marking TypedDict items as required or not.

But, the most exciting one for me is “variadic generics”. 

Check this one out if you use libraries like NumPy: https://peps.python.org/pep-0646/

In English…

The speed upgrade alone is exciting enough.

But it’s just the first stop on a longer roadmap to make Python faster (and maybe JIT compiled?).

There’s a master plan out there for Python 3.12 and beyond that has me extremely bullish on Python going forward
https://github.com/faster-cpython/ideas/tree/main/3.12

Python 3.11 release notes: https://docs.python.org/3.11/whatsnew/3.11.html

That’s it for now! I hope you find the article helpful. Thanks for reading.

Leave a Comment

Your email address will not be published.