Listen to this story
|
In a blog post today, the new features of Python 3.11 were announced. These features are expected to result in smoother user experience and provide higher performance in comparison to the 3.10 version of the programming language.
Python 3.11 is nearly 10~60% faster than Python 3.10 and measured at a 1.25x speedup on the standard benchmark suite.
The new syntax feature includes Exception Groups and except*, with built-in features of enriching exceptions with notes. New standard library modules such as tomllib would support Parsing TOML in the standard library.
The 3.11 version consists of Interpreter improvements, which includes fine grained error locations in tracebacks along with a new -P command line option. To add more, the PYTHONSAFEPATH environment variable can be used to disable—automatically prepending a potentially unsafe path (the working dir or script directory) to sys.path.
Here is an example of enhanced error locations in tracebacks:
When printing tracebacks, the interpreter will point to the exact expression that caused the error instead of just the line.
Older versions of the interpreter would point to just the line making it ambiguous which object was None. These enhanced errors are useful while dealing with deeply nested dictionary objects and multiple function calls, as well as complex arithmetic expressions.
Variadic generics is a new typing feature, along with marking individual TypedDict items as required. Others include self type, Arbitrary literal string type, and Data Class Transforms.
It also includes Important removals, deprecations, or restrictions such as removing dead batteries from the standard library or Py_UNICODE encoder APIs. It would also convert macros to functions in the Python C API.
To know more, click here.