mirror of
https://github.com/astral-sh/ruff.git
synced 2026-12-03 22:50:47 +08:00
Update/regenerate various ruff_python_stdlib APIs (#25273)
## Summary 1. Manually update various functions in `crates/ruff_python_stdlib/src/builtins.rs` to reflect new APIs added in Python 3.15. 2. Manually remove the incorrect inclusion of `frozenset` from `is_immutable_non_generic_type` in `crates/ruff_python_stdlib/src/typing.rs`. `frozenset` is a generic type. 3. Manually add `frozendict` to `is_immutable_generic_type` and `is_immutable_return_type` in `crates/ruff_python_stdlib/src/typing.rs` 4. Manually updates to `scripts/generate_builtin_modules.py`: use uv to invoke Python rather than relying on many different Python versions all being on `PATH`, drop support for Python 3.7 from the script (it can't be installed using uv), and apply various other simplifications. 5. Regenerate `is_builtin_module` in `crates/ruff_python_stdlib/src/sys/builtin_modules.rs` following the changes made in (4). Note that switching to uv-managed Python installs (PBS) appears to mean that quite a few more stdlib modules are recognised as being builtin modules, which is interesting. I also ran `scripts/generate_known_standard_library.py`, but it didn't make any changes to the Rust function generated by that script. ## Test Plan `cargo test`
This commit is contained in:
@@ -186,7 +186,12 @@ static ALWAYS_AVAILABLE_BUILTINS: &[&str] = &[
|
||||
static PY310_PLUS_BUILTINS: &[&str] = &["EncodingWarning", "aiter", "anext"];
|
||||
static PY311_PLUS_BUILTINS: &[&str] = &["BaseExceptionGroup", "ExceptionGroup"];
|
||||
static PY313_PLUS_BUILTINS: &[&str] = &["PythonFinalizationError"];
|
||||
static PY315_PLUS_BUILTINS: &[&str] = &["frozendict"];
|
||||
static PY315_PLUS_BUILTINS: &[&str] = &[
|
||||
"frozendict",
|
||||
"sentinel",
|
||||
"__lazy_import__",
|
||||
"ImportCycleError",
|
||||
];
|
||||
|
||||
/// Return the list of builtins for the given Python minor version.
|
||||
///
|
||||
@@ -410,7 +415,10 @@ pub fn is_python_builtin(name: &str, minor_version: u8, is_notebook: bool) -> bo
|
||||
) | (10.., "EncodingWarning" | "aiter" | "anext")
|
||||
| (11.., "BaseExceptionGroup" | "ExceptionGroup")
|
||||
| (13.., "PythonFinalizationError")
|
||||
| (15.., "frozendict")
|
||||
| (
|
||||
15..,
|
||||
"frozendict" | "sentinel" | "__lazy_import__" | "ImportCycleError"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -522,6 +530,6 @@ pub fn is_exception(name: &str, minor_version: u8) -> bool {
|
||||
| "UserWarning"
|
||||
) | (10.., "EncodingWarning")
|
||||
| (11.., "BaseExceptionGroup" | "ExceptionGroup")
|
||||
| (13.., "PythonFinalizationError")
|
||||
| (13.., "PythonFinalizationError" | "ImportCycleError")
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
/// modules.
|
||||
///
|
||||
/// [builtin module]: https://docs.python.org/3/library/sys.html#sys.builtin_module_names
|
||||
#[expect(clippy::unnested_or_patterns)]
|
||||
#[allow(clippy::unnested_or_patterns)]
|
||||
pub fn is_builtin_module(minor_version: u8, module: &str) -> bool {
|
||||
matches!(
|
||||
(minor_version, module),
|
||||
@@ -17,39 +17,175 @@ pub fn is_builtin_module(minor_version: u8, module: &str) -> bool {
|
||||
_,
|
||||
"_abc"
|
||||
| "_ast"
|
||||
| "_asyncio"
|
||||
| "_bisect"
|
||||
| "_blake2"
|
||||
| "_bz2"
|
||||
| "_codecs"
|
||||
| "_codecs_cn"
|
||||
| "_codecs_hk"
|
||||
| "_codecs_iso2022"
|
||||
| "_codecs_jp"
|
||||
| "_codecs_kr"
|
||||
| "_codecs_tw"
|
||||
| "_collections"
|
||||
| "_contextvars"
|
||||
| "_csv"
|
||||
| "_ctypes"
|
||||
| "_curses"
|
||||
| "_curses_panel"
|
||||
| "_datetime"
|
||||
| "_decimal"
|
||||
| "_elementtree"
|
||||
| "_functools"
|
||||
| "_hashlib"
|
||||
| "_heapq"
|
||||
| "_imp"
|
||||
| "_io"
|
||||
| "_json"
|
||||
| "_locale"
|
||||
| "_lsprof"
|
||||
| "_lzma"
|
||||
| "_md5"
|
||||
| "_multibytecodec"
|
||||
| "_multiprocessing"
|
||||
| "_opcode"
|
||||
| "_operator"
|
||||
| "_pickle"
|
||||
| "_posixshmem"
|
||||
| "_posixsubprocess"
|
||||
| "_queue"
|
||||
| "_random"
|
||||
| "_scproxy"
|
||||
| "_sha1"
|
||||
| "_sha3"
|
||||
| "_signal"
|
||||
| "_socket"
|
||||
| "_sqlite3"
|
||||
| "_sre"
|
||||
| "_ssl"
|
||||
| "_stat"
|
||||
| "_statistics"
|
||||
| "_string"
|
||||
| "_struct"
|
||||
| "_symtable"
|
||||
| "_testinternalcapi"
|
||||
| "_thread"
|
||||
| "_tracemalloc"
|
||||
| "_uuid"
|
||||
| "_warnings"
|
||||
| "_weakref"
|
||||
| "array"
|
||||
| "atexit"
|
||||
| "binascii"
|
||||
| "builtins"
|
||||
| "cmath"
|
||||
| "errno"
|
||||
| "faulthandler"
|
||||
| "fcntl"
|
||||
| "gc"
|
||||
| "grp"
|
||||
| "itertools"
|
||||
| "marshal"
|
||||
| "math"
|
||||
| "mmap"
|
||||
| "posix"
|
||||
| "pwd"
|
||||
| "pyexpat"
|
||||
| "readline"
|
||||
| "resource"
|
||||
| "select"
|
||||
| "sys"
|
||||
| "syslog"
|
||||
| "termios"
|
||||
| "time"
|
||||
) | (7, "xxsubtype" | "zipimport")
|
||||
| (8, "xxsubtype")
|
||||
| (9, "_peg_parser" | "xxsubtype")
|
||||
| (10, "xxsubtype")
|
||||
| (11, "_tokenize" | "xxsubtype")
|
||||
| (12, "_tokenize" | "_typing")
|
||||
| (13, "_suggestions" | "_sysconfig" | "_tokenize" | "_typing")
|
||||
| "unicodedata"
|
||||
| "xxsubtype"
|
||||
| "zlib"
|
||||
) | (
|
||||
8,
|
||||
"_ctypes_test" | "_dbm" | "_sha256" | "_sha512" | "_tkinter" | "audioop" | "parser"
|
||||
) | (
|
||||
9,
|
||||
"_peg_parser"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "_testbuffer"
|
||||
| "_testimportmultiple"
|
||||
| "_testmultiphase"
|
||||
| "_xxsubinterpreters"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
| "audioop"
|
||||
| "parser"
|
||||
) | (
|
||||
10,
|
||||
"_sha256" | "_sha512" | "_xxsubinterpreters" | "_xxtestfuzz" | "_zoneinfo" | "audioop"
|
||||
) | (
|
||||
11,
|
||||
"_sha256"
|
||||
| "_sha512"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_xxsubinterpreters"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
| "audioop"
|
||||
) | (
|
||||
12,
|
||||
"_sha2"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_xxinterpchannels"
|
||||
| "_xxsubinterpreters"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
| "audioop"
|
||||
) | (
|
||||
13,
|
||||
"_interpchannels"
|
||||
| "_interpqueues"
|
||||
| "_interpreters"
|
||||
| "_sha2"
|
||||
| "_suggestions"
|
||||
| "_sysconfig"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
) | (
|
||||
14,
|
||||
"_hmac"
|
||||
| "_interpchannels"
|
||||
| "_interpqueues"
|
||||
| "_interpreters"
|
||||
| "_remote_debugging"
|
||||
| "_sha2"
|
||||
| "_suggestions"
|
||||
| "_sysconfig"
|
||||
| "_tokenize"
|
||||
| "_types"
|
||||
| "_typing"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
| "_zstd"
|
||||
) | (
|
||||
15,
|
||||
"_hmac"
|
||||
| "_interpchannels"
|
||||
| "_interpqueues"
|
||||
| "_interpreters"
|
||||
| "_math_integer"
|
||||
| "_remote_debugging"
|
||||
| "_sha2"
|
||||
| "_suggestions"
|
||||
| "_sysconfig"
|
||||
| "_tokenize"
|
||||
| "_types"
|
||||
| "_typing"
|
||||
| "_xxtestfuzz"
|
||||
| "_zoneinfo"
|
||||
| "_zstd"
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -246,15 +246,7 @@ pub fn is_immutable_non_generic_type(qualified_name: &[&str]) -> bool {
|
||||
| ["typing", "LiteralString" | "Sized"]
|
||||
| [
|
||||
"",
|
||||
"bool"
|
||||
| "bytes"
|
||||
| "complex"
|
||||
| "float"
|
||||
| "frozenset"
|
||||
| "int"
|
||||
| "object"
|
||||
| "range"
|
||||
| "str"
|
||||
"bool" | "bytes" | "complex" | "float" | "int" | "object" | "range" | "str"
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -264,7 +256,7 @@ pub fn is_immutable_non_generic_type(qualified_name: &[&str]) -> bool {
|
||||
pub fn is_immutable_generic_type(qualified_name: &[&str]) -> bool {
|
||||
matches!(
|
||||
qualified_name,
|
||||
["" | "builtins", "frozenset" | "tuple"]
|
||||
["" | "builtins", "frozenset" | "tuple" | "frozendict"]
|
||||
| [
|
||||
"collections",
|
||||
"abc",
|
||||
@@ -335,6 +327,7 @@ pub fn is_immutable_return_type(qualified_name: &[&str]) -> bool {
|
||||
| "str"
|
||||
| "tuple"
|
||||
| "slice"
|
||||
| "frozendict"
|
||||
]
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user