Issue 19468: Relax the type restriction on reloaded modules (original) (raw)

Issue19468

Created on 2013-11-01 03:16 by eric.snow, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19424 merged furkanonder,2020-04-07 23:34
Messages (6)
msg201874 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-11-01 03:16
The first thing that importlib.reload() does is to verify that the passed module is an instance of types.ModuleType (Lib/importlib/__init__.py:107). This check seems unnecessary to me. We really don't have a functional need for the check (that I know of). Furthermore, there has been at least one serious proposal recently that suggested using custom module types. The only benefit that I can think of to the type check is it makes the failure more clear when someone tries to "reload" an attribute in a module (thinking just the attribute will get reloaded!). However, does that matter all that much now that reload() is not a builtin (ergo less likely to get misused very often)? I'm not invested in removing these 2 lines (or at least loosening the restriction). I've brought it up simply because it keeps staring me in the face lately. :-) If anyone has any objections, I'll drop it (at least it will be recorded here in the tracker). That said, I'm glad to remove the restriction otherwise.
msg228273 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-02 22:35
Can we or can't we remove the check as Eric has proposed in ?
msg228325 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-10-03 12:53
I think the check can be removed as long as an AttributeError is caught when trying to access module.__name__ and a message mentioning that the user probably meant to pass in a module is used, e.g.: try: name = module.__spec__.name except AttributeError: try: name = module.__name__ except AttributeError: raise TypeError("argument should be a module")
msg366211 - (view) Author: Furkan Onder (furkanonder) * Date: 2020-04-11 13:31
PR has been sent.
msg370781 - (view) Author: miss-islington (miss-islington) Date: 2020-06-05 19:56
New changeset fef1fae9df3b03510f9defb25bd0388135b4c591 by Furkan Önder in branch 'master': bpo-19468: delete unnecessary instance check in importlib.reload() (GH-19424) https://github.com/python/cpython/commit/fef1fae9df3b03510f9defb25bd0388135b4c591
msg370787 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-06-05 21:01
Thanks for the PR, Furkan !
History
Date User Action Args
2022-04-11 14:57:52 admin set github: 63667
2020-06-05 21:01:25 brett.cannon set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2020-06-05 19:56:39 miss-islington set nosy: + miss-islingtonmessages: +
2020-04-11 13:31:45 furkanonder set messages: +
2020-04-07 23:34:30 furkanonder set keywords: + patchnosy: + furkanonderpull_requests: + <pull%5Frequest18783>stage: needs patch -> patch review
2019-04-26 18:11:23 BreamoreBoy set nosy: - BreamoreBoy
2014-10-03 12:53:40 brett.cannon set messages: +
2014-10-02 22:35:30 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: + Python 3.5, - Python 3.4
2013-11-01 03:16:53 eric.snow create