Skip to content

Commit 0aca8ca

Browse files
warsawmpage
authored andcommitted
pythongh-97850: Remove all known instances of module_repr() (python#97876)
Remove all known instances of module_repr()
1 parent 9a24191 commit 0aca8ca

File tree

6 files changed

+7
-35
lines changed

6 files changed

+7
-35
lines changed

Doc/whatsnew/3.12.rst

+5
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ Removed
426426
Validation.
427427
(Contributed by Victor Stinner in :gh:`94199`.)
428428

429+
* Many previously deprecated cleanups in :mod:`importlib` have now been
430+
completed:
431+
432+
* References to, and support for ``module_repr()`` has been eradicated.
433+
429434

430435
Porting to Python 3.12
431436
======================

Lib/importlib/_bootstrap.py

-22
Original file line numberDiff line numberDiff line change
@@ -728,17 +728,6 @@ class BuiltinImporter:
728728

729729
_ORIGIN = "built-in"
730730

731-
@staticmethod
732-
def module_repr(module):
733-
"""Return repr for the module.
734-
735-
The method is deprecated. The import machinery does the job itself.
736-
737-
"""
738-
_warnings.warn("BuiltinImporter.module_repr() is deprecated and "
739-
"slated for removal in Python 3.12", DeprecationWarning)
740-
return f'<module {module.__name__!r} ({BuiltinImporter._ORIGIN})>'
741-
742731
@classmethod
743732
def find_spec(cls, fullname, path=None, target=None):
744733
if path is not None:
@@ -808,17 +797,6 @@ class FrozenImporter:
808797

809798
_ORIGIN = "frozen"
810799

811-
@staticmethod
812-
def module_repr(m):
813-
"""Return repr for the module.
814-
815-
The method is deprecated. The import machinery does the job itself.
816-
817-
"""
818-
_warnings.warn("FrozenImporter.module_repr() is deprecated and "
819-
"slated for removal in Python 3.12", DeprecationWarning)
820-
return '<module {!r} ({})>'.format(m.__name__, FrozenImporter._ORIGIN)
821-
822800
@classmethod
823801
def _fix_up_module(cls, module):
824802
spec = module.__spec__

Lib/test/test_importlib/frozen/test_loader.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def test_lacking_parent(self):
103103
expected=value))
104104
self.assertEqual(output, 'Hello world!\n')
105105

106-
def test_module_repr_indirect(self):
106+
def test_module_repr_indirect_through_spec(self):
107107
name = '__hello__'
108108
module, output = self.exec_module(name)
109109
self.assertEqual(repr(module),
@@ -190,13 +190,6 @@ def test_module_reuse(self):
190190
self.assertEqual(stdout.getvalue(),
191191
'Hello world!\nHello world!\n')
192192

193-
def test_module_repr(self):
194-
with fresh('__hello__', oldapi=True):
195-
module = self.machinery.FrozenImporter.load_module('__hello__')
196-
repr_str = self.machinery.FrozenImporter.module_repr(module)
197-
self.assertEqual(repr_str,
198-
"<module '__hello__' (frozen)>")
199-
200193
# No way to trigger an error in a frozen module.
201194
test_state_after_failure = None
202195

Lib/test/test_importlib/test_abc.py

-3
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,6 @@ def get_data(self, path):
687687
def get_filename(self, fullname):
688688
return self.path
689689

690-
def module_repr(self, module):
691-
return '<module>'
692-
693690

694691
SPLIT_SOL = make_abc_subclasses(SourceOnlyLoader, 'SourceLoader')
695692

Lib/test/test_module.py

-2
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,13 @@ def test_module_repr_with_full_loader(self):
239239
repr(m), "<module 'foo' (<class 'test.test_module.FullLoader'>)>")
240240

241241
def test_module_repr_with_bare_loader_and_filename(self):
242-
# Because the loader has no module_repr(), use the file name.
243242
m = ModuleType('foo')
244243
# Yes, a class not an instance.
245244
m.__loader__ = BareLoader
246245
m.__file__ = '/tmp/foo.py'
247246
self.assertEqual(repr(m), "<module 'foo' from '/tmp/foo.py'>")
248247

249248
def test_module_repr_with_full_loader_and_filename(self):
250-
# Even though the module has an __file__, use __loader__.module_repr()
251249
m = ModuleType('foo')
252250
# Yes, a class not an instance.
253251
m.__loader__ = FullLoader
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Long deprecated, ``module_repr()`` should now be completely eradicated.

0 commit comments

Comments
 (0)