From dbb10e8bcb01526e5f8bead09c9c3bfdfc9b71c8 Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:45:45 -0300 Subject: [PATCH 1/5] Add names from sys.stdlib_module_names (or sys.builtin_module_names for versions below 3.10) to the known stdlib modules lists. --- isort/stdlibs/py310.py | 93 ++++++++++++++++++++++++++++++++++++++++ isort/stdlibs/py311.py | 91 +++++++++++++++++++++++++++++++++++++++ isort/stdlibs/py312.py | 91 +++++++++++++++++++++++++++++++++++++++ isort/stdlibs/py38.py | 47 ++++++++++++++++++++ isort/stdlibs/py39.py | 47 ++++++++++++++++++++ scripts/mkstdlibs.py | 12 +++++- tests/unit/test_isort.py | 21 +++++++++ 7 files changed, 400 insertions(+), 2 deletions(-) diff --git a/isort/stdlibs/py310.py b/isort/stdlibs/py310.py index f45cf50a3..653ac9da1 100644 --- a/isort/stdlibs/py310.py +++ b/isort/stdlibs/py310.py @@ -6,8 +6,94 @@ """ stdlib = { + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_collections_abc", + "_compat_pickle", + "_compression", + "_contextvars", + "_crypt", + "_csv", + "_ctypes", + "_curses", + "_curses_panel", + "_datetime", + "_dbm", + "_decimal", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", + "_functools", + "_gdbm", + "_hashlib", + "_heapq", + "_imp", + "_io", + "_json", + "_locale", + "_lsprof", + "_lzma", + "_markupbase", + "_md5", + "_msi", + "_multibytecodec", + "_multiprocessing", + "_opcode", + "_operator", + "_osx_support", + "_overlapped", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydatetime", + "_pydecimal", + "_pyio", + "_pylong", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", "_thread", + "_threading_local", + "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_wmi", + "_zoneinfo", "abc", "aifc", "argparse", @@ -70,6 +156,7 @@ "ftplib", "functools", "gc", + "genericpath", "getopt", "getpass", "gettext", @@ -111,8 +198,11 @@ "netrc", "nis", "nntplib", + "nt", "ntpath", + "nturl2path", "numbers", + "opcode", "operator", "optparse", "os", @@ -136,6 +226,8 @@ "py_compile", "pyclbr", "pydoc", + "pydoc_data", + "pyexpat", "queue", "quopri", "random", @@ -190,6 +282,7 @@ "tkinter", "token", "tokenize", + "tomllib", "trace", "traceback", "tracemalloc", diff --git a/isort/stdlibs/py311.py b/isort/stdlibs/py311.py index 8f1d6e1fa..7a3998b62 100644 --- a/isort/stdlibs/py311.py +++ b/isort/stdlibs/py311.py @@ -6,9 +6,94 @@ """ stdlib = { + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_collections_abc", + "_compat_pickle", + "_compression", + "_contextvars", + "_crypt", + "_csv", + "_ctypes", + "_curses", + "_curses_panel", + "_datetime", + "_dbm", + "_decimal", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", + "_functools", + "_gdbm", + "_hashlib", + "_heapq", + "_imp", + "_io", + "_json", + "_locale", + "_lsprof", + "_lzma", + "_markupbase", + "_md5", + "_msi", + "_multibytecodec", + "_multiprocessing", + "_opcode", + "_operator", + "_osx_support", + "_overlapped", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydatetime", + "_pydecimal", + "_pyio", + "_pylong", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", "_thread", + "_threading_local", "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_wmi", + "_zoneinfo", "abc", "aifc", "argparse", @@ -70,6 +155,7 @@ "ftplib", "functools", "gc", + "genericpath", "getopt", "getpass", "gettext", @@ -111,8 +197,11 @@ "netrc", "nis", "nntplib", + "nt", "ntpath", + "nturl2path", "numbers", + "opcode", "operator", "optparse", "os", @@ -136,6 +225,8 @@ "py_compile", "pyclbr", "pydoc", + "pydoc_data", + "pyexpat", "queue", "quopri", "random", diff --git a/isort/stdlibs/py312.py b/isort/stdlibs/py312.py index cedf2a2f7..5bc5e5681 100644 --- a/isort/stdlibs/py312.py +++ b/isort/stdlibs/py312.py @@ -6,9 +6,94 @@ """ stdlib = { + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_collections_abc", + "_compat_pickle", + "_compression", + "_contextvars", + "_crypt", + "_csv", + "_ctypes", + "_curses", + "_curses_panel", + "_datetime", + "_dbm", + "_decimal", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", + "_functools", + "_gdbm", + "_hashlib", + "_heapq", + "_imp", + "_io", + "_json", + "_locale", + "_lsprof", + "_lzma", + "_markupbase", + "_md5", + "_msi", + "_multibytecodec", + "_multiprocessing", + "_opcode", + "_operator", + "_osx_support", + "_overlapped", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydatetime", + "_pydecimal", + "_pyio", + "_pylong", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", "_thread", + "_threading_local", "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_wmi", + "_zoneinfo", "abc", "aifc", "argparse", @@ -67,6 +152,7 @@ "ftplib", "functools", "gc", + "genericpath", "getopt", "getpass", "gettext", @@ -107,8 +193,11 @@ "netrc", "nis", "nntplib", + "nt", "ntpath", + "nturl2path", "numbers", + "opcode", "operator", "optparse", "os", @@ -132,6 +221,8 @@ "py_compile", "pyclbr", "pydoc", + "pydoc_data", + "pyexpat", "queue", "quopri", "random", diff --git a/isort/stdlibs/py38.py b/isort/stdlibs/py38.py index 3d89fd26b..53d54e9da 100644 --- a/isort/stdlibs/py38.py +++ b/isort/stdlibs/py38.py @@ -6,9 +6,54 @@ """ stdlib = { + "_abc", "_ast", + "_bisect", + "_blake2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_contextvars", + "_csv", + "_datetime", "_dummy_thread", + "_functools", + "_heapq", + "_imp", + "_io", + "_json", + "_locale", + "_lsprof", + "_md5", + "_multibytecodec", + "_opcode", + "_operator", + "_pickle", + "_random", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sre", + "_stat", + "_statistics", + "_string", + "_struct", + "_symtable", "_thread", + "_tokenize", + "_tracemalloc", + "_typing", + "_warnings", + "_weakref", + "_winapi", + "_xxinterpchannels", + "_xxsubinterpreters", "abc", "aifc", "argparse", @@ -112,6 +157,7 @@ "netrc", "nis", "nntplib", + "nt", "ntpath", "numbers", "operator", @@ -217,6 +263,7 @@ "xdrlib", "xml", "xmlrpc", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/isort/stdlibs/py39.py b/isort/stdlibs/py39.py index 4b7dd5954..b7d5f8792 100644 --- a/isort/stdlibs/py39.py +++ b/isort/stdlibs/py39.py @@ -6,8 +6,53 @@ """ stdlib = { + "_abc", "_ast", + "_bisect", + "_blake2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_contextvars", + "_csv", + "_datetime", + "_functools", + "_heapq", + "_imp", + "_io", + "_json", + "_locale", + "_lsprof", + "_md5", + "_multibytecodec", + "_opcode", + "_operator", + "_pickle", + "_random", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sre", + "_stat", + "_statistics", + "_string", + "_struct", + "_symtable", "_thread", + "_tokenize", + "_tracemalloc", + "_typing", + "_warnings", + "_weakref", + "_winapi", + "_xxinterpchannels", + "_xxsubinterpreters", "abc", "aifc", "argparse", @@ -111,6 +156,7 @@ "netrc", "nis", "nntplib", + "nt", "ntpath", "numbers", "operator", @@ -216,6 +262,7 @@ "xdrlib", "xml", "xmlrpc", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/scripts/mkstdlibs.py b/scripts/mkstdlibs.py index 9f375be2f..e9bb35a88 100755 --- a/scripts/mkstdlibs.py +++ b/scripts/mkstdlibs.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 +import sys + from sphinx.ext.intersphinx import fetch_inventory URL = "https://docs.python.org/{}/objects.inv" @@ -23,6 +25,7 @@ class FakeConfig: intersphinx_timeout = None tls_verify = True + tls_cacerts = () user_agent = "" @@ -40,8 +43,13 @@ class FakeApp: modules = {"_ast", "posixpath", "ntpath", "sre_constants", "sre_parse", "sre_compile", "sre"} for module in invdata["py:module"]: root, *_ = module.split(".") - if root not in ["__future__", "__main__"]: - modules.add(root) + modules.add(root) + + if version_info in {("3", "8"), ("3", "9")}: + modules |= set(sys.builtin_module_names) + else: + modules |= sys.stdlib_module_names + modules -= {"__future__", "__main__", "antigravity", "this"} path = PATH.format("".join(version_info)) with open(path, "w") as stdlib_file: diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index 7b6743c7b..ee097086d 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -5671,3 +5671,24 @@ def test_reexport_not_last_line() -> None: meme = "rickroll" """ assert isort.code(test_input, config=Config(sort_reexports=True)) == expd_output + + +@pytest.mark.skipif(sys.version_info < (3, 8), reason="builtin modules only added in 3.8 and above") +def test_builtin_modules() -> None: + test_input = ( + "from typing import Iterable, Iterator, TypeVar, cast\n" + "\n" + "from _collections_abc import dict_items, dict_keys, dict_values\n" + "from python_none_objects import NoneIterable\n" + "from _codecs import encode\n" + "from nt import environ\n" + ) + test_output = ( + "from _codecs import encode\n" + "from _collections_abc import dict_items, dict_keys, dict_values\n" + "from nt import environ\n" + "from typing import Iterable, Iterator, TypeVar, cast\n" + "\n" + "from python_none_objects import NoneIterable\n" + ) + assert isort.code(test_input) == test_output From 5bc4793c9289fb9b32b06229663e5c8222f64bb3 Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Thu, 20 Feb 2025 07:19:55 -0300 Subject: [PATCH 2/5] Fix mkstdlibs to use the stdlibs package, regenerate version files with correct module lists. --- isort/stdlibs/py310.py | 32 +++++++++++++++++----- isort/stdlibs/py311.py | 31 +++++++++++++++++++--- isort/stdlibs/py312.py | 21 +++++++++++++++ isort/stdlibs/py313.py | 55 ++++++++++++++++++++++---------------- isort/stdlibs/py39.py | 60 ++++++++++++++++++++++++++++++++++++++---- scripts/mkstdlibs.py | 25 +++++++----------- 6 files changed, 171 insertions(+), 53 deletions(-) diff --git a/isort/stdlibs/py310.py b/isort/stdlibs/py310.py index a06edb456..d92bb3283 100644 --- a/isort/stdlibs/py310.py +++ b/isort/stdlibs/py310.py @@ -6,12 +6,15 @@ """ stdlib = { + "__hello__", + "__phello__", "_abc", "_aix_support", "_ast", "_asyncio", "_bisect", "_blake2", + "_bootsubprocess", "_bz2", "_codecs", "_codecs_cn", @@ -28,6 +31,7 @@ "_crypt", "_csv", "_ctypes", + "_ctypes_test", "_curses", "_curses_panel", "_datetime", @@ -59,16 +63,15 @@ "_posixshmem", "_posixsubprocess", "_py_abc", - "_pydatetime", "_pydecimal", "_pyio", - "_pylong", "_queue", "_random", "_scproxy", "_sha1", - "_sha2", + "_sha256", "_sha3", + "_sha512", "_signal", "_sitebuiltins", "_socket", @@ -81,30 +84,39 @@ "_strptime", "_struct", "_symtable", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", "_thread", "_threading_local", "_tkinter", - "_tokenize", "_tracemalloc", - "_typing", "_uuid", "_warnings", "_weakref", "_weakrefset", "_winapi", - "_wmi", + "_xxsubinterpreters", + "_xxtestfuzz", "_zoneinfo", "abc", "aifc", "argparse", "array", "ast", + "asynchat", "asyncio", + "asyncore", "atexit", "audioop", "base64", "bdb", "binascii", + "binhex", "bisect", "builtins", "bz2", @@ -137,6 +149,7 @@ "decimal", "difflib", "dis", + "distutils", "doctest", "email", "encodings", @@ -168,6 +181,7 @@ "idlelib", "imaplib", "imghdr", + "imp", "importlib", "inspect", "io", @@ -241,6 +255,7 @@ "shutil", "signal", "site", + "smtpd", "smtplib", "sndhdr", "socket", @@ -275,7 +290,6 @@ "tkinter", "token", "tokenize", - "tomllib", "trace", "traceback", "tracemalloc", @@ -300,6 +314,10 @@ "xdrlib", "xml", "xmlrpc", + "xx", + "xxlimited", + "xxlimited_35", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/isort/stdlibs/py311.py b/isort/stdlibs/py311.py index 7dfa1f8e3..c58f90cd2 100644 --- a/isort/stdlibs/py311.py +++ b/isort/stdlibs/py311.py @@ -6,12 +6,18 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", "_abc", "_aix_support", "_ast", "_asyncio", "_bisect", "_blake2", + "_bootsubprocess", "_bz2", "_codecs", "_codecs_cn", @@ -28,6 +34,7 @@ "_crypt", "_csv", "_ctypes", + "_ctypes_test", "_curses", "_curses_panel", "_datetime", @@ -59,16 +66,15 @@ "_posixshmem", "_posixsubprocess", "_py_abc", - "_pydatetime", "_pydecimal", "_pyio", - "_pylong", "_queue", "_random", "_scproxy", "_sha1", - "_sha2", + "_sha256", "_sha3", + "_sha512", "_signal", "_sitebuiltins", "_socket", @@ -81,6 +87,13 @@ "_strptime", "_struct", "_symtable", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", "_thread", "_threading_local", "_tkinter", @@ -92,14 +105,17 @@ "_weakref", "_weakrefset", "_winapi", - "_wmi", + "_xxsubinterpreters", + "_xxtestfuzz", "_zoneinfo", "abc", "aifc", "argparse", "array", "ast", + "asynchat", "asyncio", + "asyncore", "atexit", "audioop", "base64", @@ -137,6 +153,7 @@ "decimal", "difflib", "dis", + "distutils", "doctest", "email", "encodings", @@ -168,6 +185,7 @@ "idlelib", "imaplib", "imghdr", + "imp", "importlib", "inspect", "io", @@ -241,6 +259,7 @@ "shutil", "signal", "site", + "smtpd", "smtplib", "sndhdr", "socket", @@ -300,6 +319,10 @@ "xdrlib", "xml", "xmlrpc", + "xx", + "xxlimited", + "xxlimited_35", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/isort/stdlibs/py312.py b/isort/stdlibs/py312.py index def1ad956..586b3e5d8 100644 --- a/isort/stdlibs/py312.py +++ b/isort/stdlibs/py312.py @@ -6,6 +6,11 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", "_abc", "_aix_support", "_ast", @@ -28,6 +33,7 @@ "_crypt", "_csv", "_ctypes", + "_ctypes_test", "_curses", "_curses_panel", "_datetime", @@ -81,6 +87,14 @@ "_strptime", "_struct", "_symtable", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_testsinglephase", "_thread", "_threading_local", "_tkinter", @@ -93,6 +107,9 @@ "_weakrefset", "_winapi", "_wmi", + "_xxinterpchannels", + "_xxsubinterpreters", + "_xxtestfuzz", "_zoneinfo", "abc", "aifc", @@ -300,6 +317,10 @@ "xdrlib", "xml", "xmlrpc", + "xx", + "xxlimited", + "xxlimited_35", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/isort/stdlibs/py313.py b/isort/stdlibs/py313.py index 80bfd283d..2927d35a6 100644 --- a/isort/stdlibs/py313.py +++ b/isort/stdlibs/py313.py @@ -6,8 +6,14 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", "_abc", "_aix_support", + "_android_support", "_ast", "_asyncio", "_bisect", @@ -22,12 +28,13 @@ "_codecs_tw", "_collections", "_collections_abc", + "_colorize", "_compat_pickle", "_compression", "_contextvars", - "_crypt", "_csv", "_ctypes", + "_ctypes_test", "_curses", "_curses_panel", "_datetime", @@ -41,17 +48,21 @@ "_hashlib", "_heapq", "_imp", + "_interpchannels", + "_interpqueues", + "_interpreters", "_io", + "_ios_support", "_json", "_locale", "_lsprof", "_lzma", "_markupbase", "_md5", - "_msi", "_multibytecodec", "_multiprocessing", "_opcode", + "_opcode_metadata", "_operator", "_osx_support", "_overlapped", @@ -63,6 +74,7 @@ "_pydecimal", "_pyio", "_pylong", + "_pyrepl", "_queue", "_random", "_scproxy", @@ -80,7 +92,21 @@ "_string", "_strptime", "_struct", + "_suggestions", "_symtable", + "_sysconfig", + "_testbuffer", + "_testcapi", + "_testcapi_datetime", + "_testclinic", + "_testclinic_limited", + "_testconsole", + "_testexternalinspection", + "_testimportmultiple", + "_testinternalcapi", + "_testlimitedcapi", + "_testmultiphase", + "_testsinglephase", "_thread", "_threading_local", "_tkinter", @@ -93,15 +119,14 @@ "_weakrefset", "_winapi", "_wmi", + "_xxtestfuzz", "_zoneinfo", "abc", - "aifc", "argparse", "array", "ast", "asyncio", "atexit", - "audioop", "base64", "bdb", "binascii", @@ -110,9 +135,6 @@ "bz2", "cProfile", "calendar", - "cgi", - "cgitb", - "chunk", "cmath", "cmd", "code", @@ -127,7 +149,6 @@ "contextvars", "copy", "copyreg", - "crypt", "csv", "ctypes", "curses", @@ -167,7 +188,6 @@ "http", "idlelib", "imaplib", - "imghdr", "importlib", "inspect", "io", @@ -175,24 +195,19 @@ "itertools", "json", "keyword", - "lib2to3", "linecache", "locale", "logging", "lzma", "mailbox", - "mailcap", "marshal", "math", "mimetypes", "mmap", "modulefinder", - "msilib", "msvcrt", "multiprocessing", "netrc", - "nis", - "nntplib", "nt", "ntpath", "nturl2path", @@ -201,12 +216,10 @@ "operator", "optparse", "os", - "ossaudiodev", "pathlib", "pdb", "pickle", "pickletools", - "pipes", "pkgutil", "platform", "plistlib", @@ -242,10 +255,8 @@ "signal", "site", "smtplib", - "sndhdr", "socket", "socketserver", - "spwd", "sqlite3", "sre", "sre_compile", @@ -258,14 +269,12 @@ "stringprep", "struct", "subprocess", - "sunau", "symtable", "sys", "sysconfig", "syslog", "tabnanny", "tarfile", - "telnetlib", "tempfile", "termios", "textwrap", @@ -287,7 +296,6 @@ "unicodedata", "unittest", "urllib", - "uu", "uuid", "venv", "warnings", @@ -297,9 +305,12 @@ "winreg", "winsound", "wsgiref", - "xdrlib", "xml", "xmlrpc", + "xx", + "xxlimited", + "xxlimited_35", + "xxsubtype", "zipapp", "zipfile", "zipimport", diff --git a/isort/stdlibs/py39.py b/isort/stdlibs/py39.py index 4a15df235..fdd5e47d0 100644 --- a/isort/stdlibs/py39.py +++ b/isort/stdlibs/py39.py @@ -6,10 +6,17 @@ """ stdlib = { + "__hello__", + "__phello__", "_abc", + "_aix_support", "_ast", + "_asyncio", "_bisect", "_blake2", + "_bootlocale", + "_bootsubprocess", + "_bz2", "_codecs", "_codecs_cn", "_codecs_hk", @@ -18,41 +25,85 @@ "_codecs_kr", "_codecs_tw", "_collections", + "_collections_abc", + "_compat_pickle", + "_compression", "_contextvars", + "_crypt", "_csv", + "_ctypes", + "_ctypes_test", + "_curses", + "_curses_panel", "_datetime", + "_dbm", + "_decimal", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", "_functools", + "_gdbm", + "_hashlib", "_heapq", "_imp", "_io", "_json", "_locale", "_lsprof", + "_lzma", + "_markupbase", "_md5", + "_msi", "_multibytecodec", + "_multiprocessing", "_opcode", "_operator", + "_osx_support", + "_overlapped", + "_peg_parser", "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydecimal", + "_pyio", + "_queue", "_random", + "_scproxy", "_sha1", - "_sha2", + "_sha256", "_sha3", + "_sha512", "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", "_sre", + "_ssl", "_stat", "_statistics", "_string", + "_strptime", "_struct", "_symtable", + "_testbuffer", + "_testcapi", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", "_thread", - "_tokenize", + "_threading_local", + "_tkinter", "_tracemalloc", - "_typing", + "_uuid", "_warnings", "_weakref", + "_weakrefset", "_winapi", - "_xxinterpchannels", "_xxsubinterpreters", + "_xxtestfuzz", + "_zoneinfo", "abc", "aifc", "argparse", @@ -236,7 +287,6 @@ "telnetlib", "tempfile", "termios", - "test", "textwrap", "threading", "time", diff --git a/scripts/mkstdlibs.py b/scripts/mkstdlibs.py index c42402901..9118f62e1 100755 --- a/scripts/mkstdlibs.py +++ b/scripts/mkstdlibs.py @@ -1,16 +1,14 @@ #!/usr/bin/env python3 -import sys - -from stdlibs import py39 +from stdlibs import py39, py310, py311, py312, py313 PATH = "isort/stdlibs/py{}.py" -VERSIONS = [ - ("3", "9"), - ("3", "10"), - ("3", "11"), - ("3", "12"), - ("3", "13"), -] +VERSIONS = { + ("3", "9"): py39, + ("3", "10"): py310, + ("3", "11"): py311, + ("3", "12"): py312, + ("3", "13"): py313, +} DOCSTRING = """ File contains the standard library of Python {}. @@ -19,16 +17,13 @@ using the mkstdlibs.py script. """ -for version_info in VERSIONS: +for version_info, version_module in VERSIONS.items(): version = ".".join(version_info) # Any modules we want to enforce across Python versions stdlib can be included in set init modules = {"_ast", "posixpath", "ntpath", "sre_constants", "sre_parse", "sre_compile", "sre"} - if version_info == ("3", "9"): - modules |= py39.module_names - else: - modules |= sys.stdlib_module_names + modules |= version_module.module_names modules -= {"__future__", "__main__", "antigravity", "this"} path = PATH.format("".join(version_info)) From b1dbd7983be2c68fb7330b4a67ebf897345dd03c Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Thu, 20 Feb 2025 07:22:51 -0300 Subject: [PATCH 3/5] Also regenerate py38.py. --- isort/stdlibs/py38.py | 56 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/isort/stdlibs/py38.py b/isort/stdlibs/py38.py index 6a18253fc..197d30226 100644 --- a/isort/stdlibs/py38.py +++ b/isort/stdlibs/py38.py @@ -6,10 +6,15 @@ """ stdlib = { + "__hello__", + "__phello__", "_abc", "_ast", + "_asyncio", "_bisect", "_blake2", + "_bootlocale", + "_bz2", "_codecs", "_codecs_cn", "_codecs_hk", @@ -18,42 +23,84 @@ "_codecs_kr", "_codecs_tw", "_collections", + "_collections_abc", + "_compat_pickle", + "_compression", "_contextvars", + "_crypt", "_csv", + "_ctypes", + "_ctypes_test", + "_curses", + "_curses_panel", "_datetime", + "_dbm", + "_decimal", "_dummy_thread", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", "_functools", + "_gdbm", + "_hashlib", "_heapq", "_imp", "_io", "_json", "_locale", "_lsprof", + "_lzma", + "_markupbase", "_md5", + "_msi", "_multibytecodec", + "_multiprocessing", "_opcode", "_operator", + "_osx_support", + "_overlapped", "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydecimal", + "_pyio", + "_queue", "_random", + "_scproxy", "_sha1", - "_sha2", + "_sha256", "_sha3", + "_sha512", "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", "_sre", + "_ssl", "_stat", "_statistics", "_string", + "_strptime", "_struct", "_symtable", + "_testbuffer", + "_testcapi", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", "_thread", - "_tokenize", + "_threading_local", + "_tkinter", "_tracemalloc", - "_typing", + "_uuid", "_warnings", "_weakref", + "_weakrefset", "_winapi", - "_xxinterpchannels", "_xxsubinterpreters", + "_xxtestfuzz", "abc", "aifc", "argparse", @@ -237,7 +284,6 @@ "telnetlib", "tempfile", "termios", - "test", "textwrap", "threading", "time", From e7b55269e6929eb5c6a87ce81304d5144a1c5be8 Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Sat, 29 Mar 2025 07:38:38 -0300 Subject: [PATCH 4/5] Don't remove the 'antigravity' and 'this' modules. --- isort/stdlibs/py310.py | 2 ++ isort/stdlibs/py311.py | 2 ++ isort/stdlibs/py312.py | 2 ++ isort/stdlibs/py313.py | 2 ++ isort/stdlibs/py39.py | 2 ++ scripts/mkstdlibs.py | 4 ++-- 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/isort/stdlibs/py310.py b/isort/stdlibs/py310.py index d92bb3283..182fa8657 100644 --- a/isort/stdlibs/py310.py +++ b/isort/stdlibs/py310.py @@ -105,6 +105,7 @@ "_zoneinfo", "abc", "aifc", + "antigravity", "argparse", "array", "ast", @@ -284,6 +285,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit", diff --git a/isort/stdlibs/py311.py b/isort/stdlibs/py311.py index c58f90cd2..1a9d4e4b4 100644 --- a/isort/stdlibs/py311.py +++ b/isort/stdlibs/py311.py @@ -110,6 +110,7 @@ "_zoneinfo", "abc", "aifc", + "antigravity", "argparse", "array", "ast", @@ -288,6 +289,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit", diff --git a/isort/stdlibs/py312.py b/isort/stdlibs/py312.py index 586b3e5d8..d430700a8 100644 --- a/isort/stdlibs/py312.py +++ b/isort/stdlibs/py312.py @@ -113,6 +113,7 @@ "_zoneinfo", "abc", "aifc", + "antigravity", "argparse", "array", "ast", @@ -286,6 +287,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit", diff --git a/isort/stdlibs/py313.py b/isort/stdlibs/py313.py index 2927d35a6..f99985f1c 100644 --- a/isort/stdlibs/py313.py +++ b/isort/stdlibs/py313.py @@ -122,6 +122,7 @@ "_xxtestfuzz", "_zoneinfo", "abc", + "antigravity", "argparse", "array", "ast", @@ -278,6 +279,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit", diff --git a/isort/stdlibs/py39.py b/isort/stdlibs/py39.py index fdd5e47d0..7d3fa55e9 100644 --- a/isort/stdlibs/py39.py +++ b/isort/stdlibs/py39.py @@ -106,6 +106,7 @@ "_zoneinfo", "abc", "aifc", + "antigravity", "argparse", "array", "ast", @@ -288,6 +289,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit", diff --git a/scripts/mkstdlibs.py b/scripts/mkstdlibs.py index 9118f62e1..9f2b8de9b 100755 --- a/scripts/mkstdlibs.py +++ b/scripts/mkstdlibs.py @@ -21,10 +21,10 @@ version = ".".join(version_info) # Any modules we want to enforce across Python versions stdlib can be included in set init - modules = {"_ast", "posixpath", "ntpath", "sre_constants", "sre_parse", "sre_compile", "sre"} + modules = {"_ast", "posixpath", "ntpath", "sre_parse", "sre_compile", "sre"} modules |= version_module.module_names - modules -= {"__future__", "__main__", "antigravity", "this"} + modules -= {"__future__", "__main__"} path = PATH.format("".join(version_info)) with open(path, "w") as stdlib_file: From 2f0dd4cc370bbad5ba955154bee333ca2f7b7b2d Mon Sep 17 00:00:00 2001 From: devdanzin <74280297+devdanzin@users.noreply.github.com> Date: Sat, 29 Mar 2025 07:44:40 -0300 Subject: [PATCH 5/5] Don't remove the 'antigravity' and 'this' modules in py38.py. --- isort/stdlibs/py38.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/isort/stdlibs/py38.py b/isort/stdlibs/py38.py index 197d30226..6711f84eb 100644 --- a/isort/stdlibs/py38.py +++ b/isort/stdlibs/py38.py @@ -103,6 +103,7 @@ "_xxtestfuzz", "abc", "aifc", + "antigravity", "argparse", "array", "ast", @@ -285,6 +286,7 @@ "tempfile", "termios", "textwrap", + "this", "threading", "time", "timeit",