A module or function that the standard library removed in Python 3.11 to 3.13 is used
What it finds
PEP 594 and PEP 632 removed old modules from the standard library: asynchat, asyncore, distutils, imp and smtpd in Python 3.12, and aifc, audioop, cgi, cgitb, chunk, crypt, imghdr, lib2to3, mailcap, msilib, nis, nntplib, ossaudiodev, pipes, sndhdr, spwd, sunau, telnetlib, uu and xdrlib in 3.13. Importing them raises ModuleNotFoundError on those versions. Imports inside a try block, which usually have a fallback, stubs, and files in a directory of the same name as the module, which keep their own copy of it, are not reported. Calls of inspect.getargspec, which Python 3.11 removed in favour of inspect.signature, are reported too.
From the rule's source, removed_stdlib_api.rs.
import imptx0 reports: the module imp was removed from the standard library in Python 3.12import os, telnetlibtx0 reports: the module telnetlib was removed from the standard library in Python 3.13from distutils.core import setuptx0 reports: the module distutils was removedfrom importlib import utilimport inspect try: import cgiexcept ImportError: cgi = None spec = inspect.getargspec(util)tx0 reports: inspect.getargspec was removed in Python 3.11; use inspect.signature Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:removed-stdlib-api" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:removed-stdlib-api] reason="..."tx0 explain tx0/python:removed-stdlib-api shows the same in the terminal. Found a false positive? Report it.