Skip to content

Commit e688be8

Browse files
authored
Merge branch 'main' into gh-125413-copy
2 parents fc40a79 + 37651cf commit e688be8

File tree

25 files changed

+253
-260
lines changed

25 files changed

+253
-260
lines changed

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ Objects/exceptions.c @iritkatriel
8888
**/sha* @gpshead @tiran
8989
Modules/md5* @gpshead @tiran
9090
**/*blake* @gpshead @tiran
91-
Modules/_blake2/** @gpshead @tiran
9291
Modules/_hacl/** @gpshead
9392

9493
# logging

Doc/deprecations/pending-removal-in-3.14.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Pending removal in Python 3.14
8585
:meth:`~pathlib.PurePath.relative_to`: passing additional arguments is
8686
deprecated.
8787

88-
* :mod:`pkgutil`: :func:`~pkgutil.find_loader` and :func:`~pkgutil.get_loader`
88+
* :mod:`pkgutil`: :func:`!pkgutil.find_loader` and :func:!pkgutil.get_loader`
8989
now raise :exc:`DeprecationWarning`;
9090
use :func:`importlib.util.find_spec` instead.
9191
(Contributed by Nikita Sobolev in :gh:`97850`.)

Doc/library/pkgutil.rst

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,6 @@ support.
4949
this function to raise an exception (in line with :func:`os.path.isdir`
5050
behavior).
5151

52-
.. function:: find_loader(fullname)
53-
54-
Retrieve a module :term:`loader` for the given *fullname*.
55-
56-
This is a backwards compatibility wrapper around
57-
:func:`importlib.util.find_spec` that converts most failures to
58-
:exc:`ImportError` and only returns the loader rather than the full
59-
:class:`importlib.machinery.ModuleSpec`.
60-
61-
.. versionchanged:: 3.3
62-
Updated to be based directly on :mod:`importlib` rather than relying
63-
on the package internal :pep:`302` import emulation.
64-
65-
.. versionchanged:: 3.4
66-
Updated to be based on :pep:`451`
67-
68-
.. deprecated-removed:: 3.12 3.14
69-
Use :func:`importlib.util.find_spec` instead.
70-
7152

7253
.. function:: get_importer(path_item)
7354

@@ -84,27 +65,6 @@ support.
8465
on the package internal :pep:`302` import emulation.
8566

8667

87-
.. function:: get_loader(module_or_name)
88-
89-
Get a :term:`loader` object for *module_or_name*.
90-
91-
If the module or package is accessible via the normal import mechanism, a
92-
wrapper around the relevant part of that machinery is returned. Returns
93-
``None`` if the module cannot be found or imported. If the named module is
94-
not already imported, its containing package (if any) is imported, in order
95-
to establish the package ``__path__``.
96-
97-
.. versionchanged:: 3.3
98-
Updated to be based directly on :mod:`importlib` rather than relying
99-
on the package internal :pep:`302` import emulation.
100-
101-
.. versionchanged:: 3.4
102-
Updated to be based on :pep:`451`
103-
104-
.. deprecated-removed:: 3.12 3.14
105-
Use :func:`importlib.util.find_spec` instead.
106-
107-
10868
.. function:: iter_importers(fullname='')
10969

11070
Yield :term:`finder` objects for the given module name.

Doc/library/sqlite3.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,7 @@ Some useful URI tricks include:
24422442
>>> con.execute("CREATE TABLE readonly(data)")
24432443
Traceback (most recent call last):
24442444
OperationalError: attempt to write a readonly database
2445+
>>> con.close()
24452446

24462447
* Do not implicitly create a new database file if it does not already exist;
24472448
will raise :exc:`~sqlite3.OperationalError` if unable to create a new file:

Doc/whatsnew/3.12.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ Deprecated
12291229
your code *requires* ``'fork'``. See :ref:`contexts and start methods
12301230
<multiprocessing-start-methods>`.
12311231

1232-
* :mod:`pkgutil`: :func:`pkgutil.find_loader` and :func:`pkgutil.get_loader`
1232+
* :mod:`pkgutil`: :func:`!pkgutil.find_loader` and :func:`!pkgutil.get_loader`
12331233
are deprecated and will be removed in Python 3.14;
12341234
use :func:`importlib.util.find_spec` instead.
12351235
(Contributed by Nikita Sobolev in :gh:`97850`.)

Doc/whatsnew/3.14.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,13 @@ pathlib
621621
:meth:`~pathlib.PurePath.is_relative_to`. In previous versions, any such
622622
arguments are joined onto *other*.
623623

624+
pkgutil
625+
-------
626+
627+
* Remove deprecated :func:`!pkgutil.get_loader` and :func:`!pkgutil.find_loader`.
628+
These had previously raised a :exc:`DeprecationWarning` since Python 3.12.
629+
(Contributed by Bénédikt Tran in :gh:`97850`.)
630+
624631
pty
625632
---
626633

Lib/glob.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,12 +364,6 @@ def concat_path(path, text):
364364
"""
365365
raise NotImplementedError
366366

367-
@staticmethod
368-
def parse_entry(entry):
369-
"""Returns the path of an entry yielded from scandir().
370-
"""
371-
raise NotImplementedError
372-
373367
# High-level methods
374368

375369
def compile(self, pat):
@@ -438,6 +432,7 @@ def select_wildcard(path, exists=False):
438432
except OSError:
439433
pass
440434
else:
435+
prefix = self.add_slash(path)
441436
for entry in entries:
442437
if match is None or match(entry.name):
443438
if dir_only:
@@ -446,7 +441,7 @@ def select_wildcard(path, exists=False):
446441
continue
447442
except OSError:
448443
continue
449-
entry_path = self.parse_entry(entry)
444+
entry_path = self.concat_path(prefix, entry.name)
450445
if dir_only:
451446
yield from select_next(entry_path, exists=True)
452447
else:
@@ -495,6 +490,7 @@ def select_recursive_step(stack, match_pos):
495490
except OSError:
496491
pass
497492
else:
493+
prefix = self.add_slash(path)
498494
for entry in entries:
499495
is_dir = False
500496
try:
@@ -504,7 +500,7 @@ def select_recursive_step(stack, match_pos):
504500
pass
505501

506502
if is_dir or not dir_only:
507-
entry_path = self.parse_entry(entry)
503+
entry_path = self.concat_path(prefix, entry.name)
508504
if match is None or match(str(entry_path), match_pos):
509505
if dir_only:
510506
yield from select_next(entry_path, exists=True)
@@ -533,7 +529,6 @@ class _StringGlobber(_GlobberBase):
533529
"""
534530
lexists = staticmethod(os.path.lexists)
535531
scandir = staticmethod(os.scandir)
536-
parse_entry = operator.attrgetter('path')
537532
concat_path = operator.add
538533

539534
if os.name == 'nt':

Lib/pathlib/_abc.py

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,13 @@ class PathGlobber(_GlobberBase):
198198

199199
lexists = operator.methodcaller('exists', follow_symlinks=False)
200200
add_slash = operator.methodcaller('joinpath', '')
201-
202-
@staticmethod
203-
def scandir(path):
204-
"""Emulates os.scandir(), which returns an object that can be used as
205-
a context manager. This method is called by walk() and glob().
206-
"""
207-
import contextlib
208-
return contextlib.nullcontext(path.iterdir())
201+
scandir = operator.methodcaller('scandir')
209202

210203
@staticmethod
211204
def concat_path(path, text):
212205
"""Appends text to the given path."""
213206
return path.with_segments(path._raw_path + text)
214207

215-
@staticmethod
216-
def parse_entry(entry):
217-
"""Returns the path of an entry yielded from scandir()."""
218-
return entry
219-
220208

221209
class PurePathBase:
222210
"""Base class for pure path objects.
@@ -779,16 +767,18 @@ def walk(self, top_down=True, on_error=None, follow_symlinks=False):
779767
if not top_down:
780768
paths.append((path, dirnames, filenames))
781769
try:
782-
for child in path.iterdir():
783-
try:
784-
if child.is_dir(follow_symlinks=follow_symlinks):
785-
if not top_down:
786-
paths.append(child)
787-
dirnames.append(child.name)
788-
else:
789-
filenames.append(child.name)
790-
except OSError:
791-
filenames.append(child.name)
770+
with path.scandir() as entries:
771+
for entry in entries:
772+
name = entry.name
773+
try:
774+
if entry.is_dir(follow_symlinks=follow_symlinks):
775+
if not top_down:
776+
paths.append(path.joinpath(name))
777+
dirnames.append(name)
778+
else:
779+
filenames.append(name)
780+
except OSError:
781+
filenames.append(name)
792782
except OSError as error:
793783
if on_error is not None:
794784
on_error(error)

Lib/pkgutil.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import warnings
1313

1414
__all__ = [
15-
'get_importer', 'iter_importers', 'get_loader', 'find_loader',
15+
'get_importer', 'iter_importers',
1616
'walk_packages', 'iter_modules', 'get_data',
1717
'read_code', 'extend_path',
1818
'ModuleInfo',
@@ -263,59 +263,6 @@ def iter_importers(fullname=""):
263263
yield get_importer(item)
264264

265265

266-
def get_loader(module_or_name):
267-
"""Get a "loader" object for module_or_name
268-
269-
Returns None if the module cannot be found or imported.
270-
If the named module is not already imported, its containing package
271-
(if any) is imported, in order to establish the package __path__.
272-
"""
273-
warnings._deprecated("pkgutil.get_loader",
274-
f"{warnings._DEPRECATED_MSG}; "
275-
"use importlib.util.find_spec() instead",
276-
remove=(3, 14))
277-
if module_or_name in sys.modules:
278-
module_or_name = sys.modules[module_or_name]
279-
if module_or_name is None:
280-
return None
281-
if isinstance(module_or_name, ModuleType):
282-
module = module_or_name
283-
loader = getattr(module, '__loader__', None)
284-
if loader is not None:
285-
return loader
286-
if getattr(module, '__spec__', None) is None:
287-
return None
288-
fullname = module.__name__
289-
else:
290-
fullname = module_or_name
291-
return find_loader(fullname)
292-
293-
294-
def find_loader(fullname):
295-
"""Find a "loader" object for fullname
296-
297-
This is a backwards compatibility wrapper around
298-
importlib.util.find_spec that converts most failures to ImportError
299-
and only returns the loader rather than the full spec
300-
"""
301-
warnings._deprecated("pkgutil.find_loader",
302-
f"{warnings._DEPRECATED_MSG}; "
303-
"use importlib.util.find_spec() instead",
304-
remove=(3, 14))
305-
if fullname.startswith('.'):
306-
msg = "Relative module name {!r} not supported".format(fullname)
307-
raise ImportError(msg)
308-
try:
309-
spec = importlib.util.find_spec(fullname)
310-
except (ImportError, AttributeError, TypeError, ValueError) as ex:
311-
# This hack fixes an impedance mismatch between pkgutil and
312-
# importlib, where the latter raises other errors for cases where
313-
# pkgutil previously raised ImportError
314-
msg = "Error while finding loader for {!r} ({}: {})"
315-
raise ImportError(msg.format(fullname, type(ex), ex)) from ex
316-
return spec.loader if spec is not None else None
317-
318-
319266
def extend_path(path, name):
320267
"""Extend a package's path.
321268

0 commit comments

Comments
 (0)