]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97850: Remove all known instances of module_repr() (#97876)
authorBarry Warsaw <barry@python.org>
Wed, 5 Oct 2022 18:42:26 +0000 (11:42 -0700)
committerGitHub <noreply@github.com>
Wed, 5 Oct 2022 18:42:26 +0000 (11:42 -0700)
Remove all known instances of module_repr()

Doc/whatsnew/3.12.rst
Lib/importlib/_bootstrap.py
Lib/test/test_importlib/frozen/test_loader.py
Lib/test/test_importlib/test_abc.py
Lib/test/test_module.py
Misc/NEWS.d/next/Core and Builtins/2022-10-04-17-02-18.gh-issue-97850.E3QTRA.rst [new file with mode: 0644]

index 62ec2de2e78c994507a833fae379ad68406330a2..2e9515d036e736d8560df437d4b139fe63efd335 100644 (file)
@@ -426,6 +426,11 @@ Removed
   Validation.
   (Contributed by Victor Stinner in :gh:`94199`.)
 
+* Many previously deprecated cleanups in :mod:`importlib` have now been
+  completed:
+
+  * References to, and support for ``module_repr()`` has been eradicated.
+
 
 Porting to Python 3.12
 ======================
index 67989c500f21c0b527bac8e9fa72b9c9d2ddb50d..5d3c9fe3fbd2fe1448724f9423277bb2bb1a8eb7 100644 (file)
@@ -728,17 +728,6 @@ class BuiltinImporter:
 
     _ORIGIN = "built-in"
 
-    @staticmethod
-    def module_repr(module):
-        """Return repr for the module.
-
-        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
     def find_spec(cls, fullname, path=None, target=None):
         if path is not None:
@@ -808,17 +797,6 @@ class FrozenImporter:
 
     _ORIGIN = "frozen"
 
-    @staticmethod
-    def module_repr(m):
-        """Return repr for the module.
-
-        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
     def _fix_up_module(cls, module):
         spec = module.__spec__
index 32f951cb1aca28682f8b1541aa0a44a6e0ace3c4..da1569e3d0681e5b8aa24415c16718e70c338a18 100644 (file)
@@ -103,7 +103,7 @@ class ExecModuleTests(abc.LoaderTests):
                              expected=value))
         self.assertEqual(output, 'Hello world!\n')
 
-    def test_module_repr_indirect(self):
+    def test_module_repr_indirect_through_spec(self):
         name = '__hello__'
         module, output = self.exec_module(name)
         self.assertEqual(repr(module),
@@ -190,13 +190,6 @@ class LoaderTests(abc.LoaderTests):
         self.assertEqual(stdout.getvalue(),
                          'Hello world!\nHello world!\n')
 
-    def test_module_repr(self):
-        with fresh('__hello__', oldapi=True):
-            module = self.machinery.FrozenImporter.load_module('__hello__')
-            repr_str = self.machinery.FrozenImporter.module_repr(module)
-        self.assertEqual(repr_str,
-                         "<module '__hello__' (frozen)>")
-
     # No way to trigger an error in a frozen module.
     test_state_after_failure = None
 
index c214209350a0c85db36123e1de6685a504e240b1..8641b6cc683052eb00ac08cf4ab96b3b77742627 100644 (file)
@@ -687,9 +687,6 @@ class SourceOnlyLoader:
     def get_filename(self, fullname):
         return self.path
 
-    def module_repr(self, module):
-        return '<module>'
-
 
 SPLIT_SOL = make_abc_subclasses(SourceOnlyLoader, 'SourceLoader')
 
index 6c83d76c8e3c686ce48569a6e4412ce236b20ab6..70e4efea69359a135449be65aa945a45d966aa15 100644 (file)
@@ -239,7 +239,6 @@ a = A(destroyed)"""
             repr(m), "<module 'foo' (<class 'test.test_module.FullLoader'>)>")
 
     def test_module_repr_with_bare_loader_and_filename(self):
-        # Because the loader has no module_repr(), use the file name.
         m = ModuleType('foo')
         # Yes, a class not an instance.
         m.__loader__ = BareLoader
@@ -247,7 +246,6 @@ a = A(destroyed)"""
         self.assertEqual(repr(m), "<module 'foo' from '/tmp/foo.py'>")
 
     def test_module_repr_with_full_loader_and_filename(self):
-        # Even though the module has an __file__, use __loader__.module_repr()
         m = ModuleType('foo')
         # Yes, a class not an instance.
         m.__loader__ = FullLoader
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-10-04-17-02-18.gh-issue-97850.E3QTRA.rst b/Misc/NEWS.d/next/Core and Builtins/2022-10-04-17-02-18.gh-issue-97850.E3QTRA.rst
new file mode 100644 (file)
index 0000000..f880d96
--- /dev/null
@@ -0,0 +1 @@
+Long deprecated, ``module_repr()`` should now be completely eradicated.