FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-97850: Remove all known instances of module_repr() by warsaw · Pull Request #97876 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.12.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,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
======================
Expand Down
22 changes: 0 additions & 22 deletions Lib/importlib/_bootstrap.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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__
Expand Down
9 changes: 1 addition & 8 deletions Lib/test/test_importlib/frozen/test_loader.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_lacking_parent(self):
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),
Expand Down Expand Up @@ -190,13 +190,6 @@ def test_module_reuse(self):
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

Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_importlib/test_abc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,6 @@ def get_data(self, path):
def get_filename(self, fullname):
return self.path

def module_repr(self, module):
return '<module>'


SPLIT_SOL = make_abc_subclasses(SourceOnlyLoader, 'SourceLoader')

Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_module.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -239,15 +239,13 @@ def test_module_repr_with_full_loader(self):
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
m.__file__ = '/tmp/foo.py'
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
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Long deprecated, ``module_repr()`` should now be completely eradicated.

Back | FazBrowse Home | New Git URL