From 655562e805a9b74adbb1e3faa85d97bc567dd99a Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 25 Nov 2026 23:39:05 +0000 Subject: [PATCH] fix(python): treat tomllib and newer stdlib modules as stdlib in import inference (#12670) * fix(python): treat tomllib and other 3.11+ stdlib modules as stdlib in import inference STDIMPORTS predated several modules from sys.stdlib_module_names of Python 3.11-3.14 (tomllib, annotationlib, compression, ...), so 'import tomllib' was added to requirements.in and lock generation failed. Rebuild the list as the union of those versions' module names. Co-Authored-By: Claude Opus 5.5 * fix(python): cover 3.10 and 3.15 stdlib modules in STDIMPORTS Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../windmill-parser-py-imports/src/lib.rs | 36 +++++++++++++++++-- .../windmill-parser-py-imports/tests/tests.rs | 18 ++++++++++ 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/backend/parsers/windmill-parser-py-imports/src/lib.rs b/backend/parsers/windmill-parser-py-imports/src/lib.rs index f1718c6d94..59dd565f2c 100644 --- a/backend/parsers/windmill-parser-py-imports/src/lib.rs +++ b/backend/parsers/windmill-parser-py-imports/src/lib.rs @@ -749,11 +749,17 @@ fn extract_nimports_from_content( locked_version } -const STDIMPORTS: [&str; 303] = [ +// Union of `sys.stdlib_module_names` over every `PyVAlias` version (3.10 to 3.15), `_` +// written as `-` like the inferred package names. Regenerate when a version is added; +// modules a later version removed stay, since older workers still ship them. +const STDIMPORTS: [&str; 332] = [ "--future--", "-abc", "-aix-support", + "-android-support", + "-apple-support", "-ast", + "-ast-unparse", "-asyncio", "-bisect", "-blake2", @@ -768,6 +774,7 @@ const STDIMPORTS: [&str; 303] = [ "-codecs-tw", "-collections", "-collections-abc", + "-colorize", "-compat-pickle", "-compression", "-contextvars", @@ -786,18 +793,25 @@ const STDIMPORTS: [&str; 303] = [ "-gdbm", "-hashlib", "-heapq", + "-hmac", "-imp", + "-interpchannels", + "-interpqueues", + "-interpreters", "-io", + "-ios-support", "-json", "-locale", "-lsprof", "-lzma", "-markupbase", + "-math-integer", "-md5", "-msi", "-multibytecodec", "-multiprocessing", "-opcode", + "-opcode-metadata", "-operator", "-osx-support", "-overlapped", @@ -805,11 +819,18 @@ const STDIMPORTS: [&str; 303] = [ "-posixshmem", "-posixsubprocess", "-py-abc", + "-py-warnings", + "-pydatetime", "-pydecimal", "-pyio", + "-pylong", + "-pyrepl", "-queue", "-random", + "-remote-debugging", + "-scproxy", "-sha1", + "-sha2", "-sha256", "-sha3", "-sha512", @@ -824,20 +845,27 @@ const STDIMPORTS: [&str; 303] = [ "-string", "-strptime", "-struct", + "-suggestions", "-symtable", + "-sysconfig", "-thread", "-threading-local", "-tkinter", + "-tokenize", "-tracemalloc", + "-types", + "-typing", "-uuid", "-warnings", "-weakref", "-weakrefset", "-winapi", + "-wmi", "-zoneinfo", - "zoneinfo", + "-zstd", "abc", "aifc", + "annotationlib", "antigravity", "argparse", "array", @@ -867,6 +895,7 @@ const STDIMPORTS: [&str; 303] = [ "collections", "colorsys", "compileall", + "compression", "concurrent", "configparser", "contextlib", @@ -963,6 +992,7 @@ const STDIMPORTS: [&str; 303] = [ "posixpath", "pprint", "profile", + "profiling", "pstats", "pty", "pwd", @@ -1024,6 +1054,7 @@ const STDIMPORTS: [&str; 303] = [ "tkinter", "token", "tokenize", + "tomllib", "trace", "traceback", "tracemalloc", @@ -1052,5 +1083,6 @@ const STDIMPORTS: [&str; 303] = [ "zipfile", "zipimport", "zlib", + "zoneinfo", "", ]; diff --git a/backend/parsers/windmill-parser-py-imports/tests/tests.rs b/backend/parsers/windmill-parser-py-imports/tests/tests.rs index 6d3d75a239..c1214c4140 100644 --- a/backend/parsers/windmill-parser-py-imports/tests/tests.rs +++ b/backend/parsers/windmill-parser-py-imports/tests/tests.rs @@ -157,6 +157,24 @@ def main(): Ok(()) } + #[test] + fn test_recent_stdlib_modules_not_inferred() -> anyhow::Result<()> { + let code = " +import tomllib +import annotationlib +from compression import zstd +import requests + +def main(): + return tomllib.loads(\"a = 1\") +"; + assert_eq!( + parse_code_for_imports(code, "f/foo/bar")?, + vec![auto("requests")] + ); + Ok(()) + } + #[test] fn test_parse_imports_recent_syntax_before_main() -> anyhow::Result<()> { let code = r#"