summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2021-03-26 18:55:07 (GMT)
committerGitHub <noreply@github.com>2021-03-26 18:55:07 (GMT)
commit1899087b21119c5c64cd41619b542c0bf0ab5751 (patch)
tree400c834041ef28eacaac8fa0169e2482dea8a775 /Lib
parent21a2cabb3795f5170c746ab8f29e9d25c7442550 (diff)
downloadcpython-1899087b21119c5c64cd41619b542c0bf0ab5751.zip
cpython-1899087b21119c5c64cd41619b542c0bf0ab5751.tar.gz
cpython-1899087b21119c5c64cd41619b542c0bf0ab5751.tar.bz2
bpo-42136: Deprecate module_repr() as found in importlib (GH-25022)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/importlib/_abc.py3
-rw-r--r--Lib/importlib/_bootstrap.py6
-rw-r--r--Lib/importlib/_bootstrap_external.py2
-rw-r--r--Lib/test/test_importlib/test_abc.py6
-rw-r--r--Lib/test/test_importlib/test_namespace_pkgs.py7
-rw-r--r--Lib/test/test_importlib/test_windows.py22
6 files changed, 38 insertions, 8 deletions
diff --git a/Lib/importlib/_abc.py b/Lib/importlib/_abc.py
index 7591946..f80348f 100644
--- a/Lib/importlib/_abc.py
+++ b/Lib/importlib/_abc.py
@@ -1,6 +1,7 @@
"""Subset of importlib.abc used to reduce importlib.util imports."""
from . import _bootstrap
import abc
+import warnings
class Loader(metaclass=abc.ABCMeta):
@@ -47,5 +48,7 @@ class Loader(metaclass=abc.ABCMeta):
This method is deprecated.
"""
+ warnings.warn("importlib.abc.Loader.module_repr() is deprecated and "
+ "slated for removal in Python 3.12", DeprecationWarning)
# The exception will cause ModuleType.__repr__ to ignore this method.
raise NotImplementedError
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 5038b46..d5acb65 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -302,8 +302,6 @@ def _module_repr(module):
except Exception:
pass
# Fall through to a catch-all which always succeeds.
- # We could use module.__class__.__name__ instead of 'module' in the
- # various repr permutations.
try:
name = module.__name__
except AttributeError:
@@ -741,6 +739,8 @@ class BuiltinImporter:
The method is deprecated. The import machinery does the job itself.
"""
+ _warnings.warn("BuiltinImporter.module_repr() is deprecated and "
+ "slated for removal in Python 3.12", DeprecationWarning)
return f'<module {module.__name__!r} ({BuiltinImporter._ORIGIN})>'
@classmethod
@@ -816,6 +816,8 @@ class FrozenImporter:
The method is deprecated. The import machinery does the job itself.
"""
+ _warnings.warn("FrozenImporter.module_repr() is deprecated and "
+ "slated for removal in Python 3.12", DeprecationWarning)
return '<module {!r} ({})>'.format(m.__name__, FrozenImporter._ORIGIN)
@classmethod
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 2dab45d..dac881f 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -1230,6 +1230,8 @@ class _NamespaceLoader:
The method is deprecated. The import machinery does the job itself.
"""
+ _warnings.warn("_NamespaceLoader.module_repr() is deprecated and "
+ "slated for removal in Python 3.12", DeprecationWarning)
return '<module {!r} (namespace)>'.format(module.__name__)
def is_package(self, fullname):
diff --git a/Lib/test/test_importlib/test_abc.py b/Lib/test/test_importlib/test_abc.py
index d1c89c1..6333ce8 100644
--- a/Lib/test/test_importlib/test_abc.py
+++ b/Lib/test/test_importlib/test_abc.py
@@ -220,8 +220,10 @@ class LoaderDefaultsTests(ABCTestHarness):
def test_module_repr(self):
mod = types.ModuleType('blah')
- with self.assertRaises(NotImplementedError):
- self.ins.module_repr(mod)
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ with self.assertRaises(NotImplementedError):
+ self.ins.module_repr(mod)
original_repr = repr(mod)
mod.__loader__ = self.ins
# Should still return a proper repr.
diff --git a/Lib/test/test_importlib/test_namespace_pkgs.py b/Lib/test/test_importlib/test_namespace_pkgs.py
index ab5847c..3fe3ddc 100644
--- a/Lib/test/test_importlib/test_namespace_pkgs.py
+++ b/Lib/test/test_importlib/test_namespace_pkgs.py
@@ -3,6 +3,7 @@ import importlib
import os
import sys
import unittest
+import warnings
from test.test_importlib import util
@@ -82,8 +83,10 @@ class SingleNamespacePackage(NamespacePackageTest):
def test_module_repr(self):
import foo.one
- self.assertEqual(foo.__spec__.loader.module_repr(foo),
- "<module 'foo' (namespace)>")
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore")
+ self.assertEqual(foo.__spec__.loader.module_repr(foo),
+ "<module 'foo' (namespace)>")
class DynamicPathNamespacePackage(NamespacePackageTest):
diff --git a/Lib/test/test_importlib/test_windows.py b/Lib/test/test_importlib/test_windows.py
index 8b3f200..64ffe10 100644
--- a/Lib/test/test_importlib/test_windows.py
+++ b/Lib/test/test_importlib/test_windows.py
@@ -7,7 +7,6 @@ import sys
import unittest
from test import support
from test.support import import_helper
-from distutils.util import get_platform
from contextlib import contextmanager
from .util import temp_module
@@ -18,6 +17,25 @@ from winreg import (
EnumKey, CloseKey, DeleteKey, OpenKey
)
+def get_platform():
+ # Port of distutils.util.get_platform().
+ TARGET_TO_PLAT = {
+ 'x86' : 'win32',
+ 'x64' : 'win-amd64',
+ 'arm' : 'win-arm32',
+ }
+ if ('VSCMD_ARG_TGT_ARCH' in os.environ and
+ os.environ['VSCMD_ARG_TGT_ARCH'] in TARGET_TO_PLAT):
+ return TARGET_TO_PLAT[os.environ['VSCMD_ARG_TGT_ARCH']]
+ elif 'amd64' in sys.version.lower():
+ return 'win-amd64'
+ elif '(arm)' in sys.version.lower():
+ return 'win-arm32'
+ elif '(arm64)' in sys.version.lower():
+ return 'win-arm64'
+ else:
+ return sys.platform
+
def delete_registry_tree(root, subkey):
try:
hkey = OpenKey(root, subkey, access=KEY_ALL_ACCESS)
@@ -101,7 +119,7 @@ class WindowsExtensionSuffixTests:
self.assertIn(expected_tag, suffixes)
- # Ensure the tags are in the correct order
+ # Ensure the tags are in the correct order.
tagged_i = suffixes.index(expected_tag)
self.assertLess(tagged_i, untagged_i)