Skip to content

Commit ef3cb1d

Browse files
committed
Replace and deprecate modutils.is_standard_module
1 parent 89fb7be commit ef3cb1d

File tree

6 files changed

+535
-27
lines changed

6 files changed

+535
-27
lines changed

ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Release date: TBA
1818

1919
Closes #1680
2020

21+
* Deprecate ``modutils.is_standard_module()``. It will be removed in the next minor release.
22+
Functionality has been replaced by two new functions,
23+
``modutils.is_stdlib_module()`` and ``modutils.module_in_path()``.
24+
25+
Closes #2012
26+
2127

2228
What's New in astroid 2.14.2?
2329
=============================

astroid/_stdlib.py

Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,361 @@
1+
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html
2+
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE
3+
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt
4+
5+
"""
6+
Shim to support Python versions < 3.10 that don't have sys.stdlib_module_names
7+
8+
These values were created by cherry-picking the commits from
9+
https://bugs.python.org/issue42955 into each version, but may be updated
10+
manually if changes are needed.
11+
"""
12+
13+
import sys
14+
15+
# TODO: Remove this file when Python 3.9 is no longer supported
16+
17+
# Standard library modules common to 3.7 - 3.9
18+
_COMMON = frozenset(
19+
{
20+
"__future__",
21+
"_abc",
22+
"_ast",
23+
"_asyncio",
24+
"_bisect",
25+
"_blake2",
26+
"_bootlocale",
27+
"_bz2",
28+
"_codecs",
29+
"_codecs_cn",
30+
"_codecs_hk",
31+
"_codecs_iso2022",
32+
"_codecs_jp",
33+
"_codecs_kr",
34+
"_codecs_tw",
35+
"_collections",
36+
"_collections_abc",
37+
"_compat_pickle",
38+
"_compression",
39+
"_contextvars",
40+
"_crypt",
41+
"_csv",
42+
"_ctypes",
43+
"_curses",
44+
"_curses_panel",
45+
"_datetime",
46+
"_dbm",
47+
"_decimal",
48+
"_elementtree",
49+
"_functools",
50+
"_gdbm",
51+
"_hashlib",
52+
"_heapq",
53+
"_imp",
54+
"_io",
55+
"_json",
56+
"_locale",
57+
"_lsprof",
58+
"_lzma",
59+
"_markupbase",
60+
"_md5",
61+
"_msi",
62+
"_multibytecodec",
63+
"_multiprocessing",
64+
"_opcode",
65+
"_operator",
66+
"_osx_support",
67+
"_pickle",
68+
"_posixsubprocess",
69+
"_py_abc",
70+
"_pydecimal",
71+
"_pyio",
72+
"_queue",
73+
"_random",
74+
"_sha1",
75+
"_sha256",
76+
"_sha3",
77+
"_sha512",
78+
"_signal",
79+
"_sitebuiltins",
80+
"_socket",
81+
"_sqlite3",
82+
"_sre",
83+
"_ssl",
84+
"_stat",
85+
"_string",
86+
"_strptime",
87+
"_struct",
88+
"_symtable",
89+
"_thread",
90+
"_threading_local",
91+
"_tkinter",
92+
"_tracemalloc",
93+
"_uuid",
94+
"_warnings",
95+
"_weakref",
96+
"_weakrefset",
97+
"_winapi",
98+
"abc",
99+
"aifc",
100+
"antigravity",
101+
"argparse",
102+
"array",
103+
"ast",
104+
"asynchat",
105+
"asyncio",
106+
"asyncore",
107+
"atexit",
108+
"audioop",
109+
"base64",
110+
"bdb",
111+
"binascii",
112+
"binhex",
113+
"bisect",
114+
"builtins",
115+
"bz2",
116+
"cProfile",
117+
"calendar",
118+
"cgi",
119+
"cgitb",
120+
"chunk",
121+
"cmath",
122+
"cmd",
123+
"code",
124+
"codecs",
125+
"codeop",
126+
"collections",
127+
"colorsys",
128+
"compileall",
129+
"concurrent",
130+
"configparser",
131+
"contextlib",
132+
"contextvars",
133+
"copy",
134+
"copyreg",
135+
"crypt",
136+
"csv",
137+
"ctypes",
138+
"curses",
139+
"dataclasses",
140+
"datetime",
141+
"dbm",
142+
"decimal",
143+
"difflib",
144+
"dis",
145+
"distutils",
146+
"doctest",
147+
"email",
148+
"encodings",
149+
"ensurepip",
150+
"enum",
151+
"errno",
152+
"faulthandler",
153+
"fcntl",
154+
"filecmp",
155+
"fileinput",
156+
"fnmatch",
157+
"formatter",
158+
"fractions",
159+
"ftplib",
160+
"functools",
161+
"gc",
162+
"genericpath",
163+
"getopt",
164+
"getpass",
165+
"gettext",
166+
"glob",
167+
"grp",
168+
"gzip",
169+
"hashlib",
170+
"heapq",
171+
"hmac",
172+
"html",
173+
"http",
174+
"idlelib",
175+
"imaplib",
176+
"imghdr",
177+
"imp",
178+
"importlib",
179+
"inspect",
180+
"io",
181+
"ipaddress",
182+
"itertools",
183+
"json",
184+
"keyword",
185+
"lib2to3",
186+
"linecache",
187+
"locale",
188+
"logging",
189+
"lzma",
190+
"mailbox",
191+
"mailcap",
192+
"marshal",
193+
"math",
194+
"mimetypes",
195+
"mmap",
196+
"modulefinder",
197+
"msilib",
198+
"msvcrt",
199+
"multiprocessing",
200+
"netrc",
201+
"nis",
202+
"nntplib",
203+
"nt",
204+
"ntpath",
205+
"nturl2path",
206+
"numbers",
207+
"opcode",
208+
"operator",
209+
"optparse",
210+
"os",
211+
"ossaudiodev",
212+
"parser",
213+
"pathlib",
214+
"pdb",
215+
"pickle",
216+
"pickletools",
217+
"pipes",
218+
"pkgutil",
219+
"platform",
220+
"plistlib",
221+
"poplib",
222+
"posix",
223+
"posixpath",
224+
"pprint",
225+
"profile",
226+
"pstats",
227+
"pty",
228+
"pwd",
229+
"py_compile",
230+
"pyclbr",
231+
"pydoc",
232+
"pydoc_data",
233+
"pyexpat",
234+
"queue",
235+
"quopri",
236+
"random",
237+
"re",
238+
"readline",
239+
"reprlib",
240+
"resource",
241+
"rlcompleter",
242+
"runpy",
243+
"sched",
244+
"secrets",
245+
"select",
246+
"selectors",
247+
"shelve",
248+
"shlex",
249+
"shutil",
250+
"signal",
251+
"site",
252+
"smtpd",
253+
"smtplib",
254+
"sndhdr",
255+
"socket",
256+
"socketserver",
257+
"spwd",
258+
"sqlite3",
259+
"sre_compile",
260+
"sre_constants",
261+
"sre_parse",
262+
"ssl",
263+
"stat",
264+
"statistics",
265+
"string",
266+
"stringprep",
267+
"struct",
268+
"subprocess",
269+
"sunau",
270+
"symbol",
271+
"symtable",
272+
"sys",
273+
"sysconfig",
274+
"syslog",
275+
"tabnanny",
276+
"tarfile",
277+
"telnetlib",
278+
"tempfile",
279+
"termios",
280+
"textwrap",
281+
"this",
282+
"threading",
283+
"time",
284+
"timeit",
285+
"tkinter",
286+
"token",
287+
"tokenize",
288+
"trace",
289+
"traceback",
290+
"tracemalloc",
291+
"tty",
292+
"turtle",
293+
"turtledemo",
294+
"types",
295+
"typing",
296+
"unicodedata",
297+
"unittest",
298+
"urllib",
299+
"uu",
300+
"uuid",
301+
"venv",
302+
"warnings",
303+
"wave",
304+
"weakref",
305+
"webbrowser",
306+
"winreg",
307+
"winsound",
308+
"wsgiref",
309+
"xdrlib",
310+
"xml",
311+
"xmlrpc",
312+
"zipapp",
313+
"zipfile",
314+
"zipimport",
315+
"zlib",
316+
}
317+
)
318+
319+
PY_3_7 = frozenset(
320+
_COMMON
321+
| {
322+
"_dummy_thread",
323+
"dummy_threading",
324+
"macpath",
325+
}
326+
)
327+
328+
PY_3_8 = frozenset(
329+
_COMMON
330+
| {
331+
"_dummy_thread",
332+
"_posixshmem",
333+
"_statistics",
334+
"_xxsubinterpreters",
335+
"dummy_threading",
336+
}
337+
)
338+
339+
PY_3_9 = frozenset(
340+
_COMMON
341+
| {
342+
"_aix_support",
343+
"_bootsubprocess",
344+
"_peg_parser",
345+
"_posixshmem",
346+
"_statistics",
347+
"_xxsubinterpreters",
348+
"_zoneinfo",
349+
"graphlib",
350+
"zoneinfo",
351+
}
352+
)
353+
354+
if sys.version_info[:2] == (3, 7):
355+
stdlib_module_names = PY_3_7
356+
elif sys.version_info[:2] == (3, 8):
357+
stdlib_module_names = PY_3_8
358+
elif sys.version_info[:2] == (3, 9):
359+
stdlib_module_names = PY_3_9
360+
else:
361+
stdlib_module_names = sys.stdlib_module_names

astroid/manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
get_source_file,
3131
is_module_name_part_of_extension_package_whitelist,
3232
is_python_source,
33-
is_standard_module,
33+
is_stdlib_module,
3434
load_module_from_name,
3535
modpath_from_file,
3636
)
@@ -154,7 +154,7 @@ def _build_namespace_module(
154154
def _can_load_extension(self, modname: str) -> bool:
155155
if self.always_load_extensions:
156156
return True
157-
if is_standard_module(modname):
157+
if is_stdlib_module(modname):
158158
return True
159159
return is_module_name_part_of_extension_package_whitelist(
160160
modname, self.extension_package_whitelist

0 commit comments

Comments
 (0)