Python version 3.12: what is new for developers and what prospects does 3.13 open up?

CarderPlanet

Professional
Messages
2,556
Reputation
7
Reaction score
586
Points
83
We analyze the key points of Python 3.12.

After a year of development, a significant version of the Python programming language 3.12 has been published, which will be supported for a year and a half, followed by another three and a half years of updates aimed at eliminating vulnerabilities.

The developers also launched alpha testing of Python 3.13. One of the notable features of this version is the CPython build mode, which works without a global interpreter lock (GIL). It is planned that Python 3.13 will be in alpha for 7 months, with further three-month beta testing. Before the final release, the version will be at the release candidate stage for two months.

What's new in Python 3.12?
  • Improved the flexibility of parsing f-strings (formatted literals with the ‘f ' prefix), which eliminates many restrictions. For example, you can now use any valid Python expressions inside f-strings, including multi-line expressions, comments, backslashes, and Unicode escape sequences. In addition, you can now use the same quotation marks for framing the f-string and for the inner string (i.e., you can now use double quotes inside double quotes without switching to single ones). Improved the information content of error messages in f-strings, which now show the exact location of the error in the string.
  • Improvements made for running on multi-core systems: added support for isolated subinterpreters and separate GIL (Global Interpreter Lock) for different interpreters in the same process. So far, this feature is only available via the C-API.
  • You can now use the buffer protocol in Python code . Now classes that provide the "buffer ()" method can be used as types that work directly with binary data in memory.
  • The sys.monitoring module for debugging and profiling is proposed, which allows you to monitor CPython events such as calls, returns from functions, execution of arbitrary lines of code, exceptions, and transitions with minimal overhead.
  • The interpreter has added a feature to support the Linux perf kernel, which allows you to recognize function names in Python during profiling using the perf utility.
  • Improved the detail of error messages and expanded the range of exceptions that provide tips for correcting typos. For example, it now displays recommendations for importing forgotten standard library modules, shows suggestions for adding the prefix "self." in methods, defines the spelling "import x from y" instead of "from y import x", and so on.
  • Work is underway to improve productivity, resulting in a 5% increase in efficiency.
  • Experimental support for the BOLT binary optimizer has been added to the build process, which increases performance by 1-5%.
  • Implemented inline deployment of list inclusions( comprehensions), which speeds up work with list inclusions up to two times (for code that actively uses list inclusions, testing showed an overall performance increase of 11%).
  • The size of Unicode elements has been reduced by 8-16 bytes.
  • Regular expression actions such as re.sub(), re.subn (), and re.Pattern are now faster.
  • isinstance() checks for some protocols are now 2-20 times faster.
  • The asyncio package has become significantly more efficient, with up to 75% speedup in some scenarios.
  • Faster creation of objects of the asyncio.Task class.
  • The tokenize.tokenize() and tokenize functions.generate_tokens() is significantly faster, up to 64% in some tests.
  • Faster loading of attributes and calling the super () method.
  • An improved syntax for type annotations for generalized classes and functions is provided.
  • A new way to define type aliases using the "type" expression is provided.
  • The @override decorator has been added to typing to inform type checking systems that a method in a subclass is intended to override a method or attribute in a superclass. The decorator can be used to detect errors related to the fact that the method intended for redefinition does not perform this action.
  • To enhance security, the built-in implementations of the SHA1, SHA3, SHA2-384, SHA2-512, and MD5 algorithms in hashlib have been replaced with formally verified versions from the HACL * project (built-in implementations are used only if OpenSSL is missing).
  • CPython is now protected from stack overflow.
  • pathlib.Path now supports subclasses.
  • The os module now provides extended support for Windows.
  • The sqlite3 and uuid modules now have command-line interfaces.
  • The C-API adds support for "immortal" objects that don't use reference counting.
  • Implemented the concept of an unstable C API level designed for use in debuggers, JIT compilers, and other low-level tools.
  • Cleaning of outdated components was completed.
  • The asynchat, asyncore, smtpd, imp, and distutils modules were removed (but distutils is still available in the setuptools package).
  • In the C version of unicode objects, the wstr and wstr_length attributes are excluded.
  • Deprecated methods are excluded from the unittest module.
  • We got rid of outdated and inefficient functions, classes, and methods, such as locale.format(), io_OpenWrapper, ssl.RAND_pseudo_bytes(), ElementTree.Element.copy(), hashlib.pbkdf2_hmac(), gzip.GzipFile and others.
  • Support for legacy browsers in the webbrowser module is complete, including Grail, Mosaic, Netscape, Galeon, and others up to Firefox version 36.
  • The internal representation of integer values has been revised for future optimizations.
 
Top