A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/python/cpython/commit/57c6cb5100d19a0e0218c77d887c3c239c9ce435 below:

Deprecate implementations of find_module() and find_loader… · python/cpython@57c6cb5 · GitHub

File tree Expand file treeCollapse file tree 20 files changed

+3808

-3640

lines changed

Filter options

Expand file treeCollapse file tree 20 files changed

+3808

-3640

lines changed Original file line number Diff line number Diff line change

@@ -257,6 +257,10 @@ ABC hierarchy::

257 257

Returns ``None`` when called instead of raising

258 258

:exc:`NotImplementedError`.

259 259 260 +

.. deprecated:: 3.10

261 +

Implement :meth:`MetaPathFinder.find_spec` or

262 +

:meth:`PathEntryFinder.find_spec` instead.

263 + 260 264 261 265

.. class:: MetaPathFinder

262 266

@@ -265,6 +269,9 @@ ABC hierarchy::

265 269 266 270

.. versionadded:: 3.3

267 271 272 +

.. versionchanged:: 3.10

273 +

No longer a subclass of :class:`Finder`.

274 + 268 275

.. method:: find_spec(fullname, path, target=None)

269 276 270 277

An abstract method for finding a :term:`spec <module spec>` for

@@ -313,11 +320,13 @@ ABC hierarchy::

313 320

An abstract base class representing a :term:`path entry finder`. Though

314 321

it bears some similarities to :class:`MetaPathFinder`, ``PathEntryFinder``

315 322

is meant for use only within the path-based import subsystem provided

316 -

by :class:`PathFinder`. This ABC is a subclass of :class:`Finder` for

317 -

compatibility reasons only.

323 +

by :class:`importlib.machinery.PathFinder`.

318 324 319 325

.. versionadded:: 3.3

320 326 327 +

.. versionchanged:: 3.10

328 +

No longer a subclass of :class:`Finder`.

329 + 321 330

.. method:: find_spec(fullname, target=None)

322 331 323 332

An abstract method for finding a :term:`spec <module spec>` for

@@ -363,7 +372,8 @@ ABC hierarchy::

363 372

.. method:: invalidate_caches()

364 373 365 374

An optional method which, when called, should invalidate any internal

366 -

cache used by the finder. Used by :meth:`PathFinder.invalidate_caches`

375 +

cache used by the finder. Used by

376 +

:meth:`importlib.machinery.PathFinder.invalidate_caches`

367 377

when invalidating the caches of all cached finders.

368 378 369 379

@@ -1193,6 +1203,9 @@ find and load modules.

1193 1203 1194 1204

Attempt to find the loader to handle *fullname* within :attr:`path`.

1195 1205 1206 +

.. deprecated:: 3.10

1207 +

Use :meth:`find_spec` instead.

1208 + 1196 1209

.. method:: invalidate_caches()

1197 1210 1198 1211

Clear out the internal cache.

Original file line number Diff line number Diff line change

@@ -1062,6 +1062,39 @@ Deprecated

1062 1062

:func:`importlib.util.spec_from_loader` to help in porting.

1063 1063

(Contributed by Brett Cannon in :issue:`43672`.)

1064 1064 1065 +

* The various implementations of

1066 +

:meth:`importlib.abc.MetaPathFinder.find_module` (

1067 +

:meth:`importlib.machinery.BuiltinImporter.find_module`,

1068 +

:meth:`importlib.machinery.FrozenImporter.find_module`,

1069 +

:meth:`importlib.machinery.WindowsRegistryFinder.find_module`,

1070 +

:meth:`importlib.machinery.PathFinder.find_module`,

1071 +

:meth:`importlib.abc.MetaPathFinder.find_module`),

1072 +

:meth:`importlib.abc.PathEntryFinder.find_module` (

1073 +

:meth:`importlib.machinery.FileFinder.find_module`,

1074 +

), and

1075 +

:meth:`importlib.abc.PathEntryFinder.find_loader` (

1076 +

:meth:`importlib.machinery.FileFinder.find_loader`

1077 +

) now raise :exc:`DeprecationWarning` and are slated for removal in

1078 +

Python 3.12 (previously they were documented as deprecated in Python 3.4).

1079 +

(Contributed by Brett Cannon in :issue:`42135`.)

1080 + 1081 +

* :class:`importlib.abc.Finder` is deprecated (including its sole method,

1082 +

:meth:`~importlib.abc.Finder.find_module`). Both

1083 +

:class:`importlib.abc.MetaPathFinder` and :class:`importlib.abc.PathEntryFinder`

1084 +

no longer inherit from the class. Users should inherit from one of these two

1085 +

classes as appropriate instead.

1086 +

(Contributed by Brett Cannon in :issue:`42135`.)

1087 + 1088 +

* The deprecations of :mod:`imp`, :func:`importlib.find_loader`,

1089 +

:func:`importlib.util.set_package_wrapper`,

1090 +

:func:`importlib.util.set_loader_wrapper`,

1091 +

:func:`importlib.util.module_for_loader`,

1092 +

:class:`pkgutil.ImpImporter`, and

1093 +

:class:`pkgutil.ImpLoader` have all been updated to list Python 3.12 as the

1094 +

slated version of removal (they began raising :exc:`DeprecationWarning` in

1095 +

previous versions of Python).

1096 +

(Contributed by Brett Cannon in :issue:`43720`.)

1097 + 1065 1098

* The import system now uses the ``__spec__`` attribute on modules before

1066 1099

falling back on :meth:`~importlib.abc.Loader.module_repr` for a module's

1067 1100

``__repr__()`` method. Removal of the use of ``module_repr()`` is scheduled

Original file line number Diff line number Diff line change

@@ -78,8 +78,8 @@ def find_loader(name, path=None):

78 78

This function is deprecated in favor of importlib.util.find_spec().

79 79 80 80

"""

81 -

warnings.warn('Deprecated since Python 3.4. '

82 -

'Use importlib.util.find_spec() instead.',

81 +

warnings.warn('Deprecated since Python 3.4 and slated for removal in '

82 +

'Python 3.10; use importlib.util.find_spec() instead',

83 83

DeprecationWarning, stacklevel=2)

84 84

try:

85 85

loader = sys.modules[name].__loader__

Original file line number Diff line number Diff line change

@@ -761,6 +761,9 @@ def find_module(cls, fullname, path=None):

761 761

This method is deprecated. Use find_spec() instead.

762 762 763 763

"""

764 +

_warnings.warn("BuiltinImporter.find_module() is deprecated and "

765 +

"slated for removal in Python 3.12; use find_spec() instead",

766 +

DeprecationWarning)

764 767

spec = cls.find_spec(fullname, path)

765 768

return spec.loader if spec is not None else None

766 769

@@ -834,6 +837,9 @@ def find_module(cls, fullname, path=None):

834 837

This method is deprecated. Use find_spec() instead.

835 838 836 839

"""

840 +

_warnings.warn("FrozenImporter.find_module() is deprecated and "

841 +

"slated for removal in Python 3.12; use find_spec() instead",

842 +

DeprecationWarning)

837 843

return cls if _imp.is_frozen(fullname) else None

838 844 839 845

@staticmethod

Original file line number Diff line number Diff line change

@@ -533,6 +533,9 @@ def _find_module_shim(self, fullname):

533 533

This method is deprecated in favor of finder.find_spec().

534 534 535 535

"""

536 +

_warnings.warn("find_module() is deprecated and "

537 +

"slated for removal in Python 3.12; use find_spec() instead",

538 +

DeprecationWarning)

536 539

# Call find_loader(). If it returns a string (indicating this

537 540

# is a namespace package portion), generate a warning and

538 541

# return None.

@@ -801,9 +804,12 @@ def find_spec(cls, fullname, path=None, target=None):

801 804

def find_module(cls, fullname, path=None):

802 805

"""Find module named in the registry.

803 806 804 -

This method is deprecated. Use exec_module() instead.

807 +

This method is deprecated. Use find_spec() instead.

805 808 806 809

"""

810 +

_warnings.warn("WindowsRegistryFinder.find_module() is deprecated and "

811 +

"slated for removal in Python 3.12; use find_spec() instead",

812 +

DeprecationWarning)

807 813

spec = cls.find_spec(fullname, path)

808 814

if spec is not None:

809 815

return spec.loader

@@ -1404,6 +1410,9 @@ def find_module(cls, fullname, path=None):

1404 1410

This method is deprecated. Use find_spec() instead.

1405 1411 1406 1412

"""

1413 +

_warnings.warn("PathFinder.find_module() is deprecated and "

1414 +

"slated for removal in Python 3.12; use find_spec() instead",

1415 +

DeprecationWarning)

1407 1416

spec = cls.find_spec(fullname, path)

1408 1417

if spec is None:

1409 1418

return None

@@ -1459,6 +1468,9 @@ def find_loader(self, fullname):

1459 1468

This method is deprecated. Use find_spec() instead.

1460 1469 1461 1470

"""

1471 +

_warnings.warn("FileFinder.find_loader() is deprecated and "

1472 +

"slated for removal in Python 3.12; use find_spec() instead",

1473 +

DeprecationWarning)

1462 1474

spec = self.find_spec(fullname)

1463 1475

if spec is None:

1464 1476

return None, []

Original file line number Diff line number Diff line change

@@ -41,15 +41,27 @@ class Finder(metaclass=abc.ABCMeta):

41 41

Deprecated since Python 3.3

42 42

"""

43 43 44 +

def __init__(self):

45 +

warnings.warn("the Finder ABC is deprecated and "

46 +

"slated for removal in Python 3.12; use MetaPathFinder "

47 +

"or PathEntryFinder instead",

48 +

DeprecationWarning)

49 + 44 50

@abc.abstractmethod

45 51

def find_module(self, fullname, path=None):

46 52

"""An abstract method that should find a module.

47 53

The fullname is a str and the optional path is a str or None.

48 54

Returns a Loader object or None.

49 55

"""

56 +

warnings.warn("importlib.abc.Finder along with its find_module() "

57 +

"method are deprecated and "

58 +

"slated for removal in Python 3.12; use "

59 +

"MetaPathFinder.find_spec() or "

60 +

"PathEntryFinder.find_spec() instead",

61 +

DeprecationWarning)

50 62 51 63 52 -

class MetaPathFinder(Finder):

64 +

class MetaPathFinder(metaclass=abc.ABCMeta):

53 65 54 66

"""Abstract base class for import finders on sys.meta_path."""

55 67

@@ -68,8 +80,8 @@ def find_module(self, fullname, path):

68 80 69 81

"""

70 82

warnings.warn("MetaPathFinder.find_module() is deprecated since Python "

71 -

"3.4 in favor of MetaPathFinder.find_spec() "

72 -

"(available since 3.4)",

83 +

"3.4 in favor of MetaPathFinder.find_spec() and is "

84 +

"slated for removal in Python 3.12",

73 85

DeprecationWarning,

74 86

stacklevel=2)

75 87

if not hasattr(self, 'find_spec'):

@@ -86,7 +98,7 @@ def invalidate_caches(self):

86 98

machinery.PathFinder, machinery.WindowsRegistryFinder)

87 99 88 100 89 -

class PathEntryFinder(Finder):

101 +

class PathEntryFinder(metaclass=abc.ABCMeta):

90 102 91 103

"""Abstract base class for path entry finders used by PathFinder."""

92 104 Original file line number Diff line number Diff line change

@@ -5,6 +5,7 @@

5 5 6 6

import sys

7 7

import unittest

8 +

import warnings

8 9 9 10 10 11

@unittest.skipIf(util.BUILTINS.good_name is None, 'no reasonable builtin module')

@@ -58,7 +59,9 @@ class FinderTests(abc.FinderTests):

58 59

def test_module(self):

59 60

# Common case.

60 61

with util.uncache(util.BUILTINS.good_name):

61 -

found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name)

62 +

with warnings.catch_warnings():

63 +

warnings.simplefilter("ignore", DeprecationWarning)

64 +

found = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name)

62 65

self.assertTrue(found)

63 66

self.assertTrue(hasattr(found, 'load_module'))

64 67

@@ -70,14 +73,19 @@ def test_module(self):

70 73 71 74

def test_failure(self):

72 75

assert 'importlib' not in sys.builtin_module_names

73 -

loader = self.machinery.BuiltinImporter.find_module('importlib')

76 +

with warnings.catch_warnings():

77 +

warnings.simplefilter("ignore", DeprecationWarning)

78 +

loader = self.machinery.BuiltinImporter.find_module('importlib')

74 79

self.assertIsNone(loader)

75 80 76 81

def test_ignore_path(self):

77 82

# The value for 'path' should always trigger a failed import.

78 83

with util.uncache(util.BUILTINS.good_name):

79 -

loader = self.machinery.BuiltinImporter.find_module(util.BUILTINS.good_name,

80 -

['pkg'])

84 +

with warnings.catch_warnings():

85 +

warnings.simplefilter("ignore", DeprecationWarning)

86 +

loader = self.machinery.BuiltinImporter.find_module(

87 +

util.BUILTINS.good_name,

88 +

['pkg'])

81 89

self.assertIsNone(loader)

82 90 83 91 Original file line number Diff line number Diff line change

@@ -12,30 +12,30 @@

12 12

@util.case_insensitive_tests

13 13

class ExtensionModuleCaseSensitivityTest(util.CASEOKTestBase):

14 14 15 -

def find_module(self):

15 +

def find_spec(self):

16 16

good_name = util.EXTENSIONS.name

17 17

bad_name = good_name.upper()

18 18

assert good_name != bad_name

19 19

finder = self.machinery.FileFinder(util.EXTENSIONS.path,

20 20

(self.machinery.ExtensionFileLoader,

21 21

self.machinery.EXTENSION_SUFFIXES))

22 -

return finder.find_module(bad_name)

22 +

return finder.find_spec(bad_name)

23 23 24 24

@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')

25 25

def test_case_sensitive(self):

26 26

with os_helper.EnvironmentVarGuard() as env:

27 27

env.unset('PYTHONCASEOK')

28 28

self.caseok_env_changed(should_exist=False)

29 -

loader = self.find_module()

30 -

self.assertIsNone(loader)

29 +

spec = self.find_spec()

30 +

self.assertIsNone(spec)

31 31 32 32

@unittest.skipIf(sys.flags.ignore_environment, 'ignore_environment flag was set')

33 33

def test_case_insensitivity(self):

34 34

with os_helper.EnvironmentVarGuard() as env:

35 35

env.set('PYTHONCASEOK', '1')

36 36

self.caseok_env_changed(should_exist=True)

37 -

loader = self.find_module()

38 -

self.assertTrue(hasattr(loader, 'load_module'))

37 +

spec = self.find_spec()

38 +

self.assertTrue(spec)

39 39 40 40 41 41

(Frozen_ExtensionCaseSensitivity,

Original file line number Diff line number Diff line change

@@ -11,16 +11,15 @@ class FinderTests(abc.FinderTests):

11 11 12 12

"""Test the finder for extension modules."""

13 13 14 -

def find_module(self, fullname):

14 +

def find_spec(self, fullname):

15 15

importer = self.machinery.FileFinder(util.EXTENSIONS.path,

16 16

(self.machinery.ExtensionFileLoader,

17 17

self.machinery.EXTENSION_SUFFIXES))

18 -

with warnings.catch_warnings():

19 -

warnings.simplefilter('ignore', DeprecationWarning)

20 -

return importer.find_module(fullname)

18 + 19 +

return importer.find_spec(fullname)

21 20 22 21

def test_module(self):

23 -

self.assertTrue(self.find_module(util.EXTENSIONS.name))

22 +

self.assertTrue(self.find_spec(util.EXTENSIONS.name))

24 23 25 24

# No extension module as an __init__ available for testing.

26 25

test_package = test_package_in_package = None

@@ -32,7 +31,7 @@ def test_module(self):

32 31

test_package_over_module = None

33 32 34 33

def test_failure(self):

35 -

self.assertIsNone(self.find_module('asdfjkl;'))

34 +

self.assertIsNone(self.find_spec('asdfjkl;'))

36 35 37 36 38 37

(Frozen_FinderTests,

Original file line number Diff line number Diff line change

@@ -4,6 +4,7 @@

4 4

machinery = util.import_importlib('importlib.machinery')

5 5 6 6

import unittest

7 +

import warnings

7 8 8 9 9 10

class FindSpecTests(abc.FinderTests):

@@ -49,7 +50,9 @@ class FinderTests(abc.FinderTests):

49 50 50 51

def find(self, name, path=None):

51 52

finder = self.machinery.FrozenImporter

52 -

return finder.find_module(name, path)

53 +

with warnings.catch_warnings():

54 +

warnings.simplefilter("ignore", DeprecationWarning)

55 +

return finder.find_module(name, path)

53 56 54 57

def test_module(self):

55 58

name = '__hello__'

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4