Python is a high-level interpreted programming language whose philosophy emphasizes the readability of its code.
After a year of development, the new version of the Python programming language, 3.11 , has been released. The new branch will be supported for a year and a half, after which patches will be released for another three and a half years to address vulnerabilities.
At the same time, alpha testing of the Python 3.12 branch began (according to the new development schedule, work on a new branch begins five months before the release of the previous branch and reaches the alpha testing stage at the time of the next version).
The Python 3.12 branch will be in alpha releases for seven months, during which new features will be added and bugs fixed. After that, beta testing will take place for three months, during which the addition of new features will be prohibited and full attention will be given to bug fixes. The last two months before launch, the branch will be in the launch candidate stage, at which point final stabilization will take place.
Main new features of Python 3.11
This new version includes significant work to optimize performance . The new branch incorporates changes related to acceleration and inline deployment of function calls , the use of fast interpreters for typical operations, and optimizations developed by the Cinder and HotPy projects. Depending on the workload, code execution speed increases between 10% and 60%. On average, performance on the pyperformance test suite increased by 25%.
The bytecode caching mechanism has been redesigned , reducing interpreter startup time by 10-15%. Objects containing bytecode are now statically allocated by the interpreter, eliminating the steps of decoding bytecode retrieved from the cache and converting objects containing bytecode for dynamic placement in memory.
Support for exception groups has been added , giving the program the ability to generate and process multiple different exceptions simultaneously. New exception types, ExceptionGroup and BaseExceptionGroup, are proposed for grouping and combining multiple exceptions, and the expression "except*" has been added to separate exceptions within a group.
A special LiteralString type has been added that can only include literal strings that are compatible with the LiteralString type (i.e., bare strings and strings of type LiteralString, but not arbitrary or combined strings of type str). The LiteralString type can be used to limit the passing of string arguments to functions, preventing arbitrary substitution of parts of strings where vulnerabilities can arise, for example, when generating strings for SQL queries or shell commands.
In addition, the ability to mark individual elements of typed dictionaries (TypedDict) with Required and Not Required marks is also provided to determine mandatory and optional fields (by default, all declared fields are mandatory if the total parameter is not set to False).
The class, method, and function decorator @dataclass_transform was added ; when specified, the static type checker treats the object as if it used the decorator @dataclasses.dataclass.
Of the other changes that stand out in this new version:
- Added the ability to use atomic grouping ((?>…)) and jealous (possessive) quantifiers (*+, ++, ?+, {m,n}+) in regular expressions.
- The TypeVarTuple type has been added, which allows the use of variable generics, unlike TypeVar, which covers not one type, but an arbitrary number of types.
- The standard library includes the tomllib module with functions to parse the TOML format.
- The add_note() method has been added to the BaseException class, which allows a text note to be attached to the exception, for example to add contextual information that was not available at the time the exception was thrown.
- A special type Self has been added to represent the current private class. Self can be used to annotate methods that return an instance of your class in a simpler way than using TypeVar.
- Added "-P" command line option and PYTHONSAFEPATH environment variable to disable automatic connection of potentially unsafe file paths to sys.path.
- The py.exe utility for the Windows platform has been significantly enhanced to support the "-V:" syntax. / " in addition to "- . ».
- Many C API macros have been converted to regular or static inline functions
- The uu, cgi, pipes, crypt, aifc, chunk, msilib, telnetlib, audioop, nis, sndhdr, imghdr, nntplib, spwd, xdrlib, cgitb, mailcap, ossaudiodev, and sunau modules have been deprecated and will be removed from Python. 3.13 release.
- Removed PyUnicode_Encode* functions.
- The TaskGroup class was added to the asyncio module with the implementation of an asynchronous context manager that waits for the task group to complete.
- Adding tasks to a group is done using the create_task() method.
Finally, if you are interested in learning more about this , you can find the details at the following link.