Python 3.11 arrives with performance improvements, caching redesign and more

Python

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 programming language Python 3.11 has been published, the new branch will be supported for a year and a half, after which patches with vulnerabilities will be formed for another three and a half years.

At the same time, alpha testing of the Python 3.12 branch began (according to the new development schedule, work on a new branch starts five months before the release of the previous branch and reaches alpha testing by 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

In this new version Significant work has been done to optimize performance, as the new branch includes related changes with acceleration and inline deployment of function calls, the use of fast interpreters of typical operations, as well as optimizations prepared by the Cinder and HotPy projects. Depending on the type of load, the speed of code execution increases between 10% and 60%. On average, performance when passing the pyperformance test suite increased by 25%.

The caching mechanism has been redesigned of bytecode, which reduced interpreter startup time by 10-15%. Objects with code and bytecode are now statically allocated by the interpreter, which made it possible to eliminate the steps of unraveling bytecode fetched from the cache and converting objects with code to place them in heap memory.

Added support for exception groups, which gives the program the ability to raise and process several different exceptions at the same time. New exception types ExceptionGroup and BaseExceptionGroup are proposed to group multiple exceptions together, and the expression "except* "is added to separate exceptions from a group.

Added a special LiteralString type so alone can include literal strings that are compatible with the type LiteralString (that is, bare strings and strings of type LiteralString, but not arbitrary or mixed strings of type str). The LiteralString type can be used to limit the passing of string arguments to functions, arbitrary substitution of parts of strings where it can lead to vulnerabilities, for example, when generating strings for SQL queries or shell commands.

In addition to that, also the ability to mark individual elements of dictionaries is provided (TypedDict) with Required and Not Required flags to determine required and optional fields (by default, all declared fields are required if the total parameter is not set to Fake).

Added @dataclass_transform class, method and function decorator, when specified, the static type checker treats the object as if using the @dataclasses.dataclass decorator.

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 knowing more about it, you can check the details in the following link. 


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.