Python 3.11: Faster, Better Error Msgs, Grouped Exceptions, Type Hints & More
This article will walk you through all important features of python3.11 in less than 3 minutes.
Posted: Nov. 6, 2022 • 3 mins read • Author: Adams Pierre David

Firstly, it got faster
Various speed improvements have been implemented, resulting in a faster startup in faster runtime.
Python 3.11 is an average 25% faster than 3.10, depending on your workload, speed up could be up to 10 to 60% faster.
Better error messages
The interpreter will now point to the exact expression that caused the error, instead of just the line number.
For example, here, one variable is none, so we can't access point_2.x. This is especially helpful for beginners.
The add_note method is added to base exception
It let you add additional information, which then appears in the traceback.
Here when we catch an exception we can call add_note and when this is re-raised we see the 2 notes and the traceback.
Exception groups and except *
They make it possible to group exceptions and raise them together. First, the exception group is a subclass of the normal exception, so we can get all the behavior of the base class. In an exception group, we can define multiple inner exceptions and nested exception groups. And when we raise this and look at the traceback we can easily follow the architecture of the group, then when you want to catch this we can use except * to match all the subgroups of the exception group. This allows programmers to raise and handle multiple and related exception simultaneously.
New Type Hint Features
The new literal string annotation may be used to indicate that the function parameter can be of any literal string type. Type checkers can then enforce that sensitive functions such as those that execute SQL statements are called only with static arguments, providing protection against injection attacks. Required and not required provide a straightforward way to mark whether individual items in a type that must be present.
Those two definitions are equivalent, so in this case title has to be defined and the new self annotation with a capital s provides a simple and intuitive way to annotate methods that return an instance of their class. Common use cases include alternative constructors provided as class methods.
New module : tomllib
It adds support for parsing tomml files.
Asyncio taskgroup
The asyncio task group class was added, which is an asynchronous context manager holding a group of tasks that are then awaited when the context manager exit. For new code, this is recommended over using create task and gather directly
New math functions
It got two new cool functions: math.exp2 which returns 2 raise to the power of x and math.cbrt which returns the cube root of x