mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Add a new script to generate builtin module names (#12696)
This commit is contained in:
parent
2393d19f91
commit
7ee7c68f36
7 changed files with 198 additions and 50 deletions
55
crates/ruff_python_stdlib/src/sys/builtin_modules.rs
Normal file
55
crates/ruff_python_stdlib/src/sys/builtin_modules.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
//! This file is generated by `scripts/generate_builtin_modules.py`
|
||||
|
||||
/// Return `true` if `module` is a [builtin module] on the given
|
||||
/// Python 3 version.
|
||||
///
|
||||
/// "Builtin modules" are modules that are compiled directly into the
|
||||
/// Python interpreter. These can never be shadowed by first-party
|
||||
/// modules; the normal rules of module resolution do not apply to these
|
||||
/// modules.
|
||||
///
|
||||
/// [builtin module]: https://docs.python.org/3/library/sys.html#sys.builtin_module_names
|
||||
#[allow(clippy::unnested_or_patterns)]
|
||||
pub fn is_builtin_module(minor_version: u8, module: &str) -> bool {
|
||||
matches!(
|
||||
(minor_version, module),
|
||||
(
|
||||
_,
|
||||
"_abc"
|
||||
| "_ast"
|
||||
| "_codecs"
|
||||
| "_collections"
|
||||
| "_functools"
|
||||
| "_imp"
|
||||
| "_io"
|
||||
| "_locale"
|
||||
| "_operator"
|
||||
| "_signal"
|
||||
| "_sre"
|
||||
| "_stat"
|
||||
| "_string"
|
||||
| "_symtable"
|
||||
| "_thread"
|
||||
| "_tracemalloc"
|
||||
| "_warnings"
|
||||
| "_weakref"
|
||||
| "atexit"
|
||||
| "builtins"
|
||||
| "errno"
|
||||
| "faulthandler"
|
||||
| "gc"
|
||||
| "itertools"
|
||||
| "marshal"
|
||||
| "posix"
|
||||
| "pwd"
|
||||
| "sys"
|
||||
| "time"
|
||||
) | (7, "xxsubtype" | "zipimport")
|
||||
| (8, "xxsubtype")
|
||||
| (9, "_peg_parser" | "xxsubtype")
|
||||
| (10, "xxsubtype")
|
||||
| (11, "_tokenize" | "xxsubtype")
|
||||
| (12, "_tokenize" | "_typing")
|
||||
| (13, "_suggestions" | "_sysconfig" | "_tokenize" | "_typing")
|
||||
)
|
||||
}
|
5
crates/ruff_python_stdlib/src/sys/mod.rs
Normal file
5
crates/ruff_python_stdlib/src/sys/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
mod builtin_modules;
|
||||
mod known_stdlib;
|
||||
|
||||
pub use builtin_modules::is_builtin_module;
|
||||
pub use known_stdlib::is_known_standard_library;
|
Loading…
Add table
Add a link
Reference in a new issue