mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-12 22:58:22 +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")
|
||||
)
|
||||
}
|
585
crates/ruff_python_stdlib/src/sys/known_stdlib.rs
Normal file
585
crates/ruff_python_stdlib/src/sys/known_stdlib.rs
Normal file
|
@ -0,0 +1,585 @@
|
|||
//! This file is generated by `scripts/generate_known_standard_library.py`
|
||||
|
||||
pub fn is_known_standard_library(minor_version: u8, module: &str) -> bool {
|
||||
matches!(
|
||||
(minor_version, module),
|
||||
(
|
||||
_,
|
||||
"__hello__"
|
||||
| "__phello__"
|
||||
| "_abc"
|
||||
| "_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"
|
||||
| "_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"
|
||||
| "_multibytecodec"
|
||||
| "_multiprocessing"
|
||||
| "_opcode"
|
||||
| "_operator"
|
||||
| "_osx_support"
|
||||
| "_overlapped"
|
||||
| "_pickle"
|
||||
| "_posixsubprocess"
|
||||
| "_py_abc"
|
||||
| "_pydecimal"
|
||||
| "_pyio"
|
||||
| "_queue"
|
||||
| "_random"
|
||||
| "_scproxy"
|
||||
| "_sha1"
|
||||
| "_sha3"
|
||||
| "_signal"
|
||||
| "_sitebuiltins"
|
||||
| "_socket"
|
||||
| "_sqlite3"
|
||||
| "_sre"
|
||||
| "_ssl"
|
||||
| "_stat"
|
||||
| "_string"
|
||||
| "_strptime"
|
||||
| "_struct"
|
||||
| "_symtable"
|
||||
| "_testbuffer"
|
||||
| "_testcapi"
|
||||
| "_testconsole"
|
||||
| "_testimportmultiple"
|
||||
| "_testmultiphase"
|
||||
| "_thread"
|
||||
| "_threading_local"
|
||||
| "_tkinter"
|
||||
| "_tracemalloc"
|
||||
| "_uuid"
|
||||
| "_warnings"
|
||||
| "_weakref"
|
||||
| "_weakrefset"
|
||||
| "_winapi"
|
||||
| "_xxtestfuzz"
|
||||
| "abc"
|
||||
| "antigravity"
|
||||
| "argparse"
|
||||
| "array"
|
||||
| "ast"
|
||||
| "asyncio"
|
||||
| "atexit"
|
||||
| "base64"
|
||||
| "bdb"
|
||||
| "binascii"
|
||||
| "bisect"
|
||||
| "builtins"
|
||||
| "bz2"
|
||||
| "cProfile"
|
||||
| "calendar"
|
||||
| "cmath"
|
||||
| "cmd"
|
||||
| "code"
|
||||
| "codecs"
|
||||
| "codeop"
|
||||
| "collections"
|
||||
| "colorsys"
|
||||
| "compileall"
|
||||
| "concurrent"
|
||||
| "configparser"
|
||||
| "contextlib"
|
||||
| "contextvars"
|
||||
| "copy"
|
||||
| "copyreg"
|
||||
| "csv"
|
||||
| "ctypes"
|
||||
| "curses"
|
||||
| "dataclasses"
|
||||
| "datetime"
|
||||
| "dbm"
|
||||
| "decimal"
|
||||
| "difflib"
|
||||
| "dis"
|
||||
| "doctest"
|
||||
| "email"
|
||||
| "encodings"
|
||||
| "ensurepip"
|
||||
| "enum"
|
||||
| "errno"
|
||||
| "faulthandler"
|
||||
| "fcntl"
|
||||
| "filecmp"
|
||||
| "fileinput"
|
||||
| "fnmatch"
|
||||
| "fractions"
|
||||
| "ftplib"
|
||||
| "functools"
|
||||
| "gc"
|
||||
| "genericpath"
|
||||
| "getopt"
|
||||
| "getpass"
|
||||
| "gettext"
|
||||
| "glob"
|
||||
| "grp"
|
||||
| "gzip"
|
||||
| "hashlib"
|
||||
| "heapq"
|
||||
| "hmac"
|
||||
| "html"
|
||||
| "http"
|
||||
| "idlelib"
|
||||
| "imaplib"
|
||||
| "importlib"
|
||||
| "inspect"
|
||||
| "io"
|
||||
| "ipaddress"
|
||||
| "itertools"
|
||||
| "json"
|
||||
| "keyword"
|
||||
| "linecache"
|
||||
| "locale"
|
||||
| "logging"
|
||||
| "lzma"
|
||||
| "mailbox"
|
||||
| "marshal"
|
||||
| "math"
|
||||
| "mimetypes"
|
||||
| "mmap"
|
||||
| "modulefinder"
|
||||
| "msvcrt"
|
||||
| "multiprocessing"
|
||||
| "netrc"
|
||||
| "nt"
|
||||
| "ntpath"
|
||||
| "nturl2path"
|
||||
| "numbers"
|
||||
| "opcode"
|
||||
| "operator"
|
||||
| "optparse"
|
||||
| "os"
|
||||
| "pathlib"
|
||||
| "pdb"
|
||||
| "pickle"
|
||||
| "pickletools"
|
||||
| "pkgutil"
|
||||
| "platform"
|
||||
| "plistlib"
|
||||
| "poplib"
|
||||
| "posix"
|
||||
| "posixpath"
|
||||
| "pprint"
|
||||
| "profile"
|
||||
| "pstats"
|
||||
| "pty"
|
||||
| "pwd"
|
||||
| "py_compile"
|
||||
| "pyclbr"
|
||||
| "pydoc"
|
||||
| "pydoc_data"
|
||||
| "pyexpat"
|
||||
| "queue"
|
||||
| "quopri"
|
||||
| "random"
|
||||
| "re"
|
||||
| "readline"
|
||||
| "reprlib"
|
||||
| "resource"
|
||||
| "rlcompleter"
|
||||
| "runpy"
|
||||
| "sched"
|
||||
| "secrets"
|
||||
| "select"
|
||||
| "selectors"
|
||||
| "shelve"
|
||||
| "shlex"
|
||||
| "shutil"
|
||||
| "signal"
|
||||
| "site"
|
||||
| "smtplib"
|
||||
| "socket"
|
||||
| "socketserver"
|
||||
| "sqlite3"
|
||||
| "sre_compile"
|
||||
| "sre_constants"
|
||||
| "sre_parse"
|
||||
| "ssl"
|
||||
| "stat"
|
||||
| "statistics"
|
||||
| "string"
|
||||
| "stringprep"
|
||||
| "struct"
|
||||
| "subprocess"
|
||||
| "symtable"
|
||||
| "sys"
|
||||
| "sysconfig"
|
||||
| "syslog"
|
||||
| "tabnanny"
|
||||
| "tarfile"
|
||||
| "tempfile"
|
||||
| "termios"
|
||||
| "textwrap"
|
||||
| "this"
|
||||
| "threading"
|
||||
| "time"
|
||||
| "timeit"
|
||||
| "tkinter"
|
||||
| "token"
|
||||
| "tokenize"
|
||||
| "trace"
|
||||
| "traceback"
|
||||
| "tracemalloc"
|
||||
| "tty"
|
||||
| "turtle"
|
||||
| "turtledemo"
|
||||
| "types"
|
||||
| "typing"
|
||||
| "unicodedata"
|
||||
| "unittest"
|
||||
| "urllib"
|
||||
| "uuid"
|
||||
| "venv"
|
||||
| "warnings"
|
||||
| "wave"
|
||||
| "weakref"
|
||||
| "webbrowser"
|
||||
| "winreg"
|
||||
| "winsound"
|
||||
| "wsgiref"
|
||||
| "xml"
|
||||
| "xmlrpc"
|
||||
| "xx"
|
||||
| "xxlimited"
|
||||
| "xxsubtype"
|
||||
| "zipapp"
|
||||
| "zipfile"
|
||||
| "zipimport"
|
||||
| "zlib"
|
||||
) | (
|
||||
7,
|
||||
"_bootlocale"
|
||||
| "_crypt"
|
||||
| "_dummy_thread"
|
||||
| "_msi"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "aifc"
|
||||
| "asynchat"
|
||||
| "asyncore"
|
||||
| "audioop"
|
||||
| "binhex"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "distutils"
|
||||
| "dummy_threading"
|
||||
| "formatter"
|
||||
| "imghdr"
|
||||
| "imp"
|
||||
| "lib2to3"
|
||||
| "macpath"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "parser"
|
||||
| "pipes"
|
||||
| "smtpd"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "symbol"
|
||||
| "telnetlib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
) | (
|
||||
8,
|
||||
"_bootlocale"
|
||||
| "_crypt"
|
||||
| "_dummy_thread"
|
||||
| "_msi"
|
||||
| "_posixshmem"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "_statistics"
|
||||
| "_testinternalcapi"
|
||||
| "_xxsubinterpreters"
|
||||
| "aifc"
|
||||
| "asynchat"
|
||||
| "asyncore"
|
||||
| "audioop"
|
||||
| "binhex"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "distutils"
|
||||
| "dummy_threading"
|
||||
| "formatter"
|
||||
| "imghdr"
|
||||
| "imp"
|
||||
| "lib2to3"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "parser"
|
||||
| "pipes"
|
||||
| "smtpd"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "symbol"
|
||||
| "telnetlib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
) | (
|
||||
9,
|
||||
"_aix_support"
|
||||
| "_bootlocale"
|
||||
| "_bootsubprocess"
|
||||
| "_crypt"
|
||||
| "_msi"
|
||||
| "_peg_parser"
|
||||
| "_posixshmem"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "_statistics"
|
||||
| "_testinternalcapi"
|
||||
| "_xxsubinterpreters"
|
||||
| "_zoneinfo"
|
||||
| "aifc"
|
||||
| "asynchat"
|
||||
| "asyncore"
|
||||
| "audioop"
|
||||
| "binhex"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "distutils"
|
||||
| "formatter"
|
||||
| "graphlib"
|
||||
| "imghdr"
|
||||
| "imp"
|
||||
| "lib2to3"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "parser"
|
||||
| "peg_parser"
|
||||
| "pipes"
|
||||
| "smtpd"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "symbol"
|
||||
| "telnetlib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
| "zoneinfo"
|
||||
) | (
|
||||
10,
|
||||
"_aix_support"
|
||||
| "_bootsubprocess"
|
||||
| "_crypt"
|
||||
| "_msi"
|
||||
| "_posixshmem"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "_statistics"
|
||||
| "_testclinic"
|
||||
| "_testinternalcapi"
|
||||
| "_xxsubinterpreters"
|
||||
| "_zoneinfo"
|
||||
| "aifc"
|
||||
| "asynchat"
|
||||
| "asyncore"
|
||||
| "audioop"
|
||||
| "binhex"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "distutils"
|
||||
| "graphlib"
|
||||
| "imghdr"
|
||||
| "imp"
|
||||
| "lib2to3"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "pipes"
|
||||
| "smtpd"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "telnetlib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
| "xxlimited_35"
|
||||
| "zoneinfo"
|
||||
) | (
|
||||
11,
|
||||
"__hello_alias__"
|
||||
| "__hello_only__"
|
||||
| "__phello_alias__"
|
||||
| "_aix_support"
|
||||
| "_bootsubprocess"
|
||||
| "_crypt"
|
||||
| "_msi"
|
||||
| "_posixshmem"
|
||||
| "_sha256"
|
||||
| "_sha512"
|
||||
| "_statistics"
|
||||
| "_testclinic"
|
||||
| "_testinternalcapi"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_xxsubinterpreters"
|
||||
| "_zoneinfo"
|
||||
| "aifc"
|
||||
| "asynchat"
|
||||
| "asyncore"
|
||||
| "audioop"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "distutils"
|
||||
| "graphlib"
|
||||
| "imghdr"
|
||||
| "imp"
|
||||
| "lib2to3"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "pipes"
|
||||
| "smtpd"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "telnetlib"
|
||||
| "tomllib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
| "xxlimited_35"
|
||||
| "zoneinfo"
|
||||
) | (
|
||||
12,
|
||||
"__hello_alias__"
|
||||
| "__hello_only__"
|
||||
| "__phello_alias__"
|
||||
| "_aix_support"
|
||||
| "_crypt"
|
||||
| "_msi"
|
||||
| "_posixshmem"
|
||||
| "_pydatetime"
|
||||
| "_pylong"
|
||||
| "_sha2"
|
||||
| "_statistics"
|
||||
| "_testclinic"
|
||||
| "_testinternalcapi"
|
||||
| "_testsinglephase"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_xxinterpchannels"
|
||||
| "_xxsubinterpreters"
|
||||
| "_zoneinfo"
|
||||
| "aifc"
|
||||
| "audioop"
|
||||
| "cgi"
|
||||
| "cgitb"
|
||||
| "chunk"
|
||||
| "crypt"
|
||||
| "graphlib"
|
||||
| "imghdr"
|
||||
| "lib2to3"
|
||||
| "mailcap"
|
||||
| "msilib"
|
||||
| "nis"
|
||||
| "nntplib"
|
||||
| "ossaudiodev"
|
||||
| "pipes"
|
||||
| "sndhdr"
|
||||
| "spwd"
|
||||
| "sunau"
|
||||
| "telnetlib"
|
||||
| "tomllib"
|
||||
| "uu"
|
||||
| "xdrlib"
|
||||
| "xxlimited_35"
|
||||
| "zoneinfo"
|
||||
) | (
|
||||
13,
|
||||
"__hello_alias__"
|
||||
| "__hello_only__"
|
||||
| "__phello_alias__"
|
||||
| "_aix_support"
|
||||
| "_android_support"
|
||||
| "_colorize"
|
||||
| "_interpchannels"
|
||||
| "_interpqueues"
|
||||
| "_interpreters"
|
||||
| "_ios_support"
|
||||
| "_opcode_metadata"
|
||||
| "_posixshmem"
|
||||
| "_pydatetime"
|
||||
| "_pylong"
|
||||
| "_pyrepl"
|
||||
| "_sha2"
|
||||
| "_statistics"
|
||||
| "_suggestions"
|
||||
| "_sysconfig"
|
||||
| "_testclinic"
|
||||
| "_testclinic_limited"
|
||||
| "_testexternalinspection"
|
||||
| "_testinternalcapi"
|
||||
| "_testlimitedcapi"
|
||||
| "_testsinglephase"
|
||||
| "_tokenize"
|
||||
| "_typing"
|
||||
| "_zoneinfo"
|
||||
| "graphlib"
|
||||
| "tomllib"
|
||||
| "xxlimited_35"
|
||||
| "zoneinfo"
|
||||
)
|
||||
)
|
||||
}
|
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