Collaboration on handling Python 3.12 incompatible changes (distutils and asyncore removal, invalid escape escape, etc.)


I removed many deprecated functions of the Python API and C API in Python 3.12. I prefer to do it as soon as possible at the beginning of the Python 3.12 release cycle. This way, we can collect more feedback and earlier, have more time to update affected projects, and also have more time to decide if some changes should be reverted or not. See What’s New In Python 3.12 — Python 3.12.0a1 documentation for all changes. Examples:

  • Remove the infamous distutils package: install setuptools to get setuptools’ favor of distutils (and enjoy subtle differences with the removed flavor!)
  • Remove ssl.wrap_socket(): use ssl.SSLContext.wrap_socket() instead, it’s more secure.
  • "\d", "\477" and other invalid escape sequence now emit SyntaxWarning instead of DeprecationWarning. Run pycodestyle --select W605 $(find project/ -name "*.py") to find affected strings of your project/ directory.

I created this thread to collaborate on handling Python 3.12 incompatible changes. If you are affected or if you want to help, you’re welcome here! If you dislike these changes, that’s also the right place to give your feedback.



the setuptools vendored distutils has diverged somewhat from the stdlib version

here’s some of the issues that’ve personally affected me though I suspect there’s more that I’m not remembering:

I suspect the migration is going to be a bit rocky due to this

If setuptools 60 or newer is installed, distutils is provided by setuptools. It’s the setuptools/_distutils/ module. Example:

$ /opt/py312/bin/python3 
Python 3.12.0a1+ (heads/main:f09da28768, Nov  4 2022, 17:46:22) [GCC 12.2.1 20220819 (Red Hat 12.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import distutils
>>> distutils
<module 'distutils' (/opt/py312/lib/python3.12/site-packages/setuptools/_distutils/>

It is made possible thanks to distutils-precedence.pth file installed by setuptools.

There is a bug on Python 3.12 (without distutils): if pip is imported first, import setuptools and import distutils fails since _distutils_hack looks for the stdlib distutils instead. I reported the bug #3661 to setuptools.

My colleague Miro Hrončok @hroncok is working on Fedora to prepare Python packages for the distutils removal:

1 Like

There is a small issue with setuptools in Python 3.12: setuptools: distutils cannot be imported on Python 3.12 (without distutils) if pip was imported.

Another Python 3.12 incompatible change: asyncore, asynchat and smtpd modules, deprecated since Python 3.6, are removed in Python 3.12: issue #72719.

1 Like

There are also quite a lot of things removed (and in-the-process of removal) in importlib, pkgutil, and imp modules. See: