Python 3.12.0 Alpha 6 What’s Coming ?

Sarper Makas
Mobile App Circular
3 min readMar 11, 2023

As you may remember, I wrote an article about What’s New in Python 3.11, which looked at new features and improvements to the language with code examples. But now, today, we will look at what we are getting with Python 3.12.0 Alpha 6, which was released on March 7, 2023. We are going to cover new features of the 3.12 series compared to 3.11.

Python 3.12a6

What is 3.12.0a6

Python 3.12 is still in development. But today we are going to look at Python 3.12.0a6, which is the sixth of seven planned alpha releases.

The aim of the alpha releases is to make it easier to test the current state of new features and bug fixes that come with it for giving us a bug-free version in the future.

During the alpha versions, features may be added up until the start of the beta versions (2023–05–08, which is not so far) and deleted or modified up until the candidate versions if necessary. Do not forget that Python 3.12.0a6 is a preview release, which is not recommended for production environments.

What’s Coming ?

Improved Error Messages

As you may know, with the power of Python 3.11, you can raise multiple exceptions by using exception groups, and you can also add notes to your exceptions, which helps you give detailed information easily about your exception.

With Python 3.12.0a6, we will get more improved error messages and more exceptions, which might be caused by typos, that make suggestions to the user for flexibility.

When a NameError is raised to the top level, modules from the standard library are now optionally proposed as part of the error messages presented by the interpreter. Pablo Galindo contributed to gh-98254.

>>> sys.version_info
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'sys' is not defined. Did you forget to import 'sys'?
class A:

def __init__(self):

self.blech = 1


def foo(self):

somethin = blech
>>> A().foo()
File "<stdin>", line 1
somethin = blech
^^^^^
NameError: name 'blech' is not defined. Did you mean: 'self.blech'?

Enhance the SyntaxError warning message when the user inputs import x from y rather than import x from y. Pablo Galindo contributed to gh-98931.

>>> import a.y.z from b.y.z  
File "<stdin>", line 1
import a.y.z from b.y.z
^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Did you mean to use 'from ... import ...' instead?

ImportError exceptions caused by unsuccessful from module> import name> statements now offer name> value suggestions based on the names available in module>. Pablo Galindo contributed to gh-91058.

>>> from collections import chainmap
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'chainmap' from 'collections'. Did you mean: 'ChainMap'?

,Linux “perf” Profile Support

Linux perf profilers support reporting Python function names in traces.

“Wstr” and “wstr_length”

wstr and wstr_length members of the C implementation of unicode objects are going to be removed, per PEP 623.

Unittest Module

A number of long deprecated methods and classes were removed which had been deprecated since Python 3.1 or 3.2 is removed from unittest module.

Removed Modules, Classes, Functions, Methods

smtpd and distutils (which are deprecated) modules have been removed (look at PEP 594 and PEP 632). The distutils module is still going to provide the setuptools package, which is installed by default in virtualenvs and many other places.

Some of the functions, classes, and methods that are old, broken, and deprecated have been removed.

Backslash Escapes

From now on, backslash escape sequences in strings are warned with SyntaxWarning instead of DeprecationWarning.

Integers

In preparation for performance improvements, the internal representation of integers has altered. (As an internal detail, this should not effect most users, but it may cause problems for Cython-generated code.)

New Modules

No new modules were released.

Improved Modules

Source

https://docs.python.org/dev/whatsnew/3.12.html

--

--