Skip to content

Commit 4bec6bb

Browse files
authored
Updated the pkgutil + unittest libraries + the pkgutil, unittest and import tests - v.3.13.11 (#6610)
* Updated unittest + tests * Updated pkgutil + the associated test * Updated test_import * Fixed import + unittest test errors * Updated test_dll_dependency_import with expectedFailure
1 parent eee3608 commit 4bec6bb

File tree

22 files changed

+2373
-267
lines changed

22 files changed

+2373
-267
lines changed

Lib/pkgutil.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
__all__ = [
1515
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
1616
'walk_packages', 'iter_modules', 'get_data',
17-
'ImpImporter', 'ImpLoader', 'read_code', 'extend_path',
17+
'read_code', 'extend_path',
1818
'ModuleInfo',
1919
]
2020

@@ -23,20 +23,6 @@
2323
ModuleInfo.__doc__ = 'A namedtuple with minimal info about a module.'
2424

2525

26-
def _get_spec(finder, name):
27-
"""Return the finder-specific module spec."""
28-
# Works with legacy finders.
29-
try:
30-
find_spec = finder.find_spec
31-
except AttributeError:
32-
loader = finder.find_module(name)
33-
if loader is None:
34-
return None
35-
return importlib.util.spec_from_loader(name, loader)
36-
else:
37-
return find_spec(name)
38-
39-
4026
def read_code(stream):
4127
# This helper is needed in order for the PEP 302 emulation to
4228
# correctly handle compiled files
@@ -184,6 +170,7 @@ def _iter_file_finder_modules(importer, prefix=''):
184170
iter_importer_modules.register(
185171
importlib.machinery.FileFinder, _iter_file_finder_modules)
186172

173+
187174
try:
188175
import zipimport
189176
from zipimport import zipimporter
@@ -231,6 +218,7 @@ def get_importer(path_item):
231218
The cache (or part of it) can be cleared manually if a
232219
rescan of sys.path_hooks is necessary.
233220
"""
221+
path_item = os.fsdecode(path_item)
234222
try:
235223
importer = sys.path_importer_cache[path_item]
236224
except KeyError:
@@ -282,6 +270,10 @@ def get_loader(module_or_name):
282270
If the named module is not already imported, its containing package
283271
(if any) is imported, in order to establish the package __path__.
284272
"""
273+
warnings._deprecated("pkgutil.get_loader",
274+
f"{warnings._DEPRECATED_MSG}; "
275+
"use importlib.util.find_spec() instead",
276+
remove=(3, 14))
285277
if module_or_name in sys.modules:
286278
module_or_name = sys.modules[module_or_name]
287279
if module_or_name is None:
@@ -306,6 +298,10 @@ def find_loader(fullname):
306298
importlib.util.find_spec that converts most failures to ImportError
307299
and only returns the loader rather than the full spec
308300
"""
301+
warnings._deprecated("pkgutil.find_loader",
302+
f"{warnings._DEPRECATED_MSG}; "
303+
"use importlib.util.find_spec() instead",
304+
remove=(3, 14))
309305
if fullname.startswith('.'):
310306
msg = "Relative module name {!r} not supported".format(fullname)
311307
raise ImportError(msg)
@@ -328,10 +324,10 @@ def extend_path(path, name):
328324
from pkgutil import extend_path
329325
__path__ = extend_path(__path__, __name__)
330326
331-
This will add to the package's __path__ all subdirectories of
332-
directories on sys.path named after the package. This is useful
333-
if one wants to distribute different parts of a single logical
334-
package as multiple directories.
327+
For each directory on sys.path that has a subdirectory that
328+
matches the package name, add the subdirectory to the package's
329+
__path__. This is useful if one wants to distribute different
330+
parts of a single logical package as multiple directories.
335331
336332
It also looks for *.pkg files beginning where * matches the name
337333
argument. This feature is similar to *.pth files (see site.py),

0 commit comments

Comments
 (0)