Debian Codegraph @

friendly_traceback/runtime_errors/stdlib_modules.py

raw symbols SCIP
1 """Names of base modules found in the standard library,
2 that do not start with an underscore.
3
4 This list is not authoritative but should be good enough.
5
6 Note that some module might not be found on some platform.
7 See function ``module_exists`` at the end.
8 """
9
10 import sys
11 from importlib.util import find_spec
12
13 if hasattr(sys, "stdlib_module_names"): # Python 3.10+
14 # convert to set from frozenset, so we can add mocks for tests.
15 names = set(sys.stdlib_module_names) # type: ignore[import]
16 else:
17 names = {
18 "abc",
19 "aifc",
20 "antigravity",
21 "argparse",
22 "array",
23 "ast",
24 "asynchat",
25 "asyncio",
26 "asyncore",
27 "atexit",
28 "audioop",
29 "base64",
30 "bdb",
31 "binascii",
32 "binhex",
33 "bisect",
34 "builtins",
35 "bz2",
36 "cProfile",
37 "calendar",
38 "cgi",
39 "cgitb",
40 "chunk",
41 "cmath",
42 "cmd",
43 "code",
44 "codecs",
45 "codeop",
46 "collections",
47 "colorsys",
48 "compileall",
49 "concurrent",
50 "configparser",
51 "contextlib",
52 "contextvars",
53 "copy",
54 "copyreg",
55 "crypt",
56 "csv",
57 "ctypes",
58 "curses",
59 "dataclasses",
60 "datetime",
61 "dbm",
62 "decimal",
63 "difflib",
64 "dis",
65 "distutils",
66 "doctest",
67 "email",
68 "encodings",
69 "ensurepip",
70 "enum",
71 "errno",
72 "faulthandler",
73 "fcntl",
74 "filecmp",
75 "fileinput",
76 "fnmatch",
77 "formatter",
78 "fpectl",
79 "fractions",
80 "ftplib",
81 "functools",
82 "gc",
83 "genericpath",
84 "getopt",
85 "getpass",
86 "gettext",
87 "glob",
88 "graphlib",
89 "grp",
90 "gzip",
91 "hashlib",
92 "heapq",
93 "hmac",
94 "html",
95 "http",
96 "idlelib",
97 "imaplib",
98 "imghdr",
99 "imp",
100 "importlib",
101 "inspect",
102 "io",
103 "ipaddress",
104 "itertools",
105 "json",
106 "keyword",
107 "lib2to3",
108 "linecache",
109 "locale",
110 "logging",
111 "lzma",
112 "macpath",
113 "macurl2path",
114 "mailbox",
115 "mailcap",
116 "marshal",
117 "math",
118 "mimetypes",
119 "mmap",
120 "modulefinder",
121 "msilib",
122 "msvcrt",
123 "multiprocessing",
124 "netrc",
125 "nis",
126 "nntplib",
127 "ntpath",
128 "nturl2path",
129 "numbers",
130 "opcode",
131 "operator",
132 "optparse",
133 "os",
134 "ossaudiodev",
135 "parser",
136 "pathlib",
137 "pdb",
138 "pickle",
139 "pickletools",
140 "pipes",
141 "pkgutil",
142 "platform",
143 "plistlib",
144 "poplib",
145 "posix",
146 "posixpath",
147 "pprint",
148 "profile",
149 "pstats",
150 "pty",
151 "pwd",
152 "py_compile",
153 "pyclbr",
154 "pydoc",
155 "pydoc_data",
156 "pyexpat",
157 "queue",
158 "quopri",
159 "random",
160 "re",
161 "readline",
162 "reprlib",
163 "resource",
164 "rlcompleter",
165 "runpy",
166 "sched",
167 "secrets",
168 "select",
169 "selectors",
170 "shelve",
171 "shlex",
172 "shutil",
173 "signal",
174 "site",
175 "smtpd",
176 "smtplib",
177 "sndhdr",
178 "socket",
179 "socketserver",
180 "spwd",
181 "sqlite3",
182 "sre_compile",
183 "sre_constants",
184 "sre_parse",
185 "ssl",
186 "stat",
187 "statistics",
188 "string",
189 "stringprep",
190 "struct",
191 "subprocess",
192 "sunau",
193 "symbol",
194 "symtable",
195 "sys",
196 "sysconfig",
197 "syslog",
198 "tabnanny",
199 "tarfile",
200 "telnetlib",
201 "tempfile",
202 "termios",
203 "textwrap",
204 "this",
205 "threading",
206 "time",
207 "timeit",
208 "tkinter",
209 "token",
210 "tokenize",
211 "trace",
212 "traceback",
213 "tracemalloc",
214 "tty",
215 "turtle",
216 "turtledemo",
217 "types",
218 "typing",
219 "unicodedata",
220 "unittest",
221 "urllib",
222 "uu",
223 "uuid",
224 "venv",
225 "warnings",
226 "wave",
227 "weakref",
228 "webbrowser",
229 "winreg",
230 "winsound",
231 "wsgiref",
232 "xdrlib",
233 "xml",
234 "xmlrpc",
235 "xxlimited",
236 "xxsubtype",
237 "zipapp",
238 "zipfile",
239 "zipimport",
240 "zlib",
241 "zoneinfo",
242 }
243
244
245 def module_exists(name):
246 found = False
247 if name in names:
248 name_spec = find_spec(name)
249 found = name_spec is not None
250 return found