diff --git a/isort/stdlibs/py310.py b/isort/stdlibs/py310.py index f6769965..182fa865 100644 --- a/isort/stdlibs/py310.py +++ b/isort/stdlibs/py310.py @@ -6,7 +6,103 @@ """ stdlib = { + "__hello__", + "__phello__", + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bootsubprocess", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_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", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydecimal", + "_pyio", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha256", + "_sha3", + "_sha512", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_thread", + "_threading_local", + "_tkinter", + "_tracemalloc", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_xxsubinterpreters", + "_xxtestfuzz", + "_zoneinfo", "abc", "aifc", "antigravity", diff --git a/isort/stdlibs/py311.py b/isort/stdlibs/py311.py index 9f50ec85..1a9d4e4b 100644 --- a/isort/stdlibs/py311.py +++ b/isort/stdlibs/py311.py @@ -6,7 +6,108 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bootsubprocess", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_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", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydecimal", + "_pyio", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha256", + "_sha3", + "_sha512", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_thread", + "_threading_local", + "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_xxsubinterpreters", + "_xxtestfuzz", + "_zoneinfo", "abc", "aifc", "antigravity", diff --git a/isort/stdlibs/py312.py b/isort/stdlibs/py312.py index 7feac7fe..d430700a 100644 --- a/isort/stdlibs/py312.py +++ b/isort/stdlibs/py312.py @@ -6,7 +6,111 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", + "_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", + "_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", + "_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", + "_testbuffer", + "_testcapi", + "_testclinic", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_testsinglephase", + "_thread", + "_threading_local", + "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_wmi", + "_xxinterpchannels", + "_xxsubinterpreters", + "_xxtestfuzz", + "_zoneinfo", "abc", "aifc", "antigravity", diff --git a/isort/stdlibs/py313.py b/isort/stdlibs/py313.py index 9015a187..f99985f1 100644 --- a/isort/stdlibs/py313.py +++ b/isort/stdlibs/py313.py @@ -6,7 +6,121 @@ """ stdlib = { + "__hello__", + "__hello_alias__", + "__hello_only__", + "__phello__", + "__phello_alias__", + "_abc", + "_aix_support", + "_android_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_codecs_kr", + "_codecs_tw", + "_collections", + "_collections_abc", + "_colorize", + "_compat_pickle", + "_compression", + "_contextvars", + "_csv", + "_ctypes", + "_ctypes_test", + "_curses", + "_curses_panel", + "_datetime", + "_dbm", + "_decimal", + "_elementtree", + "_frozen_importlib", + "_frozen_importlib_external", + "_functools", + "_gdbm", + "_hashlib", + "_heapq", + "_imp", + "_interpchannels", + "_interpqueues", + "_interpreters", + "_io", + "_ios_support", + "_json", + "_locale", + "_lsprof", + "_lzma", + "_markupbase", + "_md5", + "_multibytecodec", + "_multiprocessing", + "_opcode", + "_opcode_metadata", + "_operator", + "_osx_support", + "_overlapped", + "_pickle", + "_posixshmem", + "_posixsubprocess", + "_py_abc", + "_pydatetime", + "_pydecimal", + "_pyio", + "_pylong", + "_pyrepl", + "_queue", + "_random", + "_scproxy", + "_sha1", + "_sha2", + "_sha3", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_suggestions", + "_symtable", + "_sysconfig", + "_testbuffer", + "_testcapi", + "_testcapi_datetime", + "_testclinic", + "_testclinic_limited", + "_testconsole", + "_testexternalinspection", + "_testimportmultiple", + "_testinternalcapi", + "_testlimitedcapi", + "_testmultiphase", + "_testsinglephase", + "_thread", + "_threading_local", + "_tkinter", + "_tokenize", + "_tracemalloc", + "_typing", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_wmi", + "_xxtestfuzz", + "_zoneinfo", "abc", "antigravity", "argparse", diff --git a/isort/stdlibs/py38.py b/isort/stdlibs/py38.py index bf2cdf29..6711f84e 100644 --- a/isort/stdlibs/py38.py +++ b/isort/stdlibs/py38.py @@ -6,7 +6,101 @@ """ stdlib = { + "__hello__", + "__phello__", + "_abc", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bootlocale", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_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", + "_sha256", + "_sha3", + "_sha512", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", + "_testbuffer", + "_testcapi", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_thread", + "_threading_local", + "_tkinter", + "_tracemalloc", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_xxsubinterpreters", + "_xxtestfuzz", "abc", "aifc", "antigravity", diff --git a/isort/stdlibs/py39.py b/isort/stdlibs/py39.py index 7615952c..7d3fa55e 100644 --- a/isort/stdlibs/py39.py +++ b/isort/stdlibs/py39.py @@ -6,7 +6,104 @@ """ stdlib = { + "__hello__", + "__phello__", + "_abc", + "_aix_support", "_ast", + "_asyncio", + "_bisect", + "_blake2", + "_bootlocale", + "_bootsubprocess", + "_bz2", + "_codecs", + "_codecs_cn", + "_codecs_hk", + "_codecs_iso2022", + "_codecs_jp", + "_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", + "_sha256", + "_sha3", + "_sha512", + "_signal", + "_sitebuiltins", + "_socket", + "_sqlite3", + "_sre", + "_ssl", + "_stat", + "_statistics", + "_string", + "_strptime", + "_struct", + "_symtable", + "_testbuffer", + "_testcapi", + "_testconsole", + "_testimportmultiple", + "_testinternalcapi", + "_testmultiphase", + "_thread", + "_threading_local", + "_tkinter", + "_tracemalloc", + "_uuid", + "_warnings", + "_weakref", + "_weakrefset", + "_winapi", + "_xxsubinterpreters", + "_xxtestfuzz", + "_zoneinfo", "abc", "aifc", "antigravity", diff --git a/scripts/mkstdlibs.py b/scripts/mkstdlibs.py index 22ae5582..9f2b8de9 100755 --- a/scripts/mkstdlibs.py +++ b/scripts/mkstdlibs.py @@ -1,18 +1,14 @@ #!/usr/bin/env python3 -import re +from stdlibs import py39, py310, py311, py312, py313 -from stdlibs import py38, py39, py310, py311, py312, py313 - -URL = "https://docs.python.org/{}/objects.inv" PATH = "isort/stdlibs/py{}.py" -VERSIONS = [ - py38, - py39, - py310, - py311, - py312, - py313, -] +VERSIONS = { + ("3", "9"): py39, + ("3", "10"): py310, + ("3", "11"): py311, + ("3", "12"): py312, + ("3", "13"): py313, +} DOCSTRING = """ File contains the standard library of Python {}. @@ -21,39 +17,18 @@ using the mkstdlibs.py script. """ - -class FakeConfig: - intersphinx_timeout = None - tls_verify = True - user_agent = "" - tls_cacerts = None - - -class FakeApp: - srcdir = "" - config = FakeConfig() - - -for version_module in VERSIONS: - version_match = re.match( - r"^stdlibs\.py(?P\d)(?P\d+)$", - version_module.__name__, - ) - version_info = (version_match.groupdict()["major"], version_match.groupdict()["minor"]) +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"} - modules.update( - { - module_name - for module_name in version_module.module_names - if not module_name.startswith("_") - } - ) + modules = {"_ast", "posixpath", "ntpath", "sre_parse", "sre_compile", "sre"} + + modules |= version_module.module_names + modules -= {"__future__", "__main__"} path = PATH.format("".join(version_info)) with open(path, "w") as stdlib_file: - docstring = DOCSTRING.format(".".join(version_info)) + docstring = DOCSTRING.format(version) stdlib_file.write(f'"""{docstring}"""\n\n') stdlib_file.write("stdlib = {\n") for module in sorted(modules): diff --git a/tests/unit/test_isort.py b/tests/unit/test_isort.py index e72f1fee..97b1592d 100644 --- a/tests/unit/test_isort.py +++ b/tests/unit/test_isort.py @@ -5741,3 +5741,24 @@ def test_reexport_multiline_long_rollback() -> None: test """ 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