This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Prefer using __spec__ over module_repr() for ModuleType.__repr__
Type: behavior Stage: resolved
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon
Priority: normal Keywords: patch

Created on 2020-10-23 23:20 by brett.cannon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 24953 merged brett.cannon, 2021-03-21 02:51
Messages (5)
msg379496 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-10-23 23:20
Once all traces of module_repr() are gone, raise an `ImportWarning` when using `module_repr()`.

Once this is implemented and has been out in the wild for a sufficient amount of time, it should be switching to a DeprecationWarning and then the fallback eventually removed.
msg389177 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-03-20 20:04
Should try to use __spec__ first, but if it isn't set then fall back on module_repr() and raise an ImportWarning. See Lib/importlib/_bootstrap.py:_module_repr.
msg389206 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-03-21 02:28
Thinking about it more, raising ImportWarning (or DeprecationWarning) is unnecessarily noisy as the existence of the module isn't problematic, it just won't be used anymore in the future. So updating the code to use __spec__ first and then document in "What's New" should be good enough.
msg389326 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-03-22 15:50
Meant to say, "existence of the _method_ isn't problematic".
msg389470 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2021-03-24 15:27
New changeset 9cb31d671646a5ff0901f79d2d61022621447190 by Brett Cannon in branch 'master':
bpo-42137: have ModuleType.__repr__ prefer __spec__ over module_repr() (GH-24953)
https://github.com/python/cpython/commit/9cb31d671646a5ff0901f79d2d61022621447190
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86303
2021-03-24 15:27:17brett.cannonsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-03-24 15:27:04brett.cannonsetmessages: + msg389470
2021-03-22 15:50:21brett.cannonsetmessages: + msg389326
2021-03-21 02:51:19brett.cannonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request23711
2021-03-21 02:41:53brett.cannonsetdependencies: - [importlib] deprecate module_repr() methods
2021-03-21 02:28:45brett.cannonsetassignee: brett.cannon
messages: + msg389206
title: Raise an ImportWarning for calling module_repr() on loaders -> Prefer using __spec__ over module_repr() for ModuleType.__repr__
2021-03-20 20:04:50brett.cannonsetmessages: + msg389177
2020-10-23 23:21:03brett.cannonsetdependencies: + [importlib] deprecate module_repr() methods
2020-10-23 23:20:55brett.cannoncreate