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.

Title: Relax the type restriction on reloaded modules
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.5
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, eric.snow, furkanonder, miss-islington, ncoghlan
Priority: normal Keywords: patch

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/  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 msg201874?
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.:

    name =
except AttributeError:
        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)
msg370787 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-06-05 21:01
Thanks for the PR, Furkan !
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63667
2020-06-05 21:01:25brett.cannonsetstatus: open -> closed
resolution: fixed
messages: + msg370787

stage: patch review -> resolved
2020-06-05 19:56:39miss-islingtonsetnosy: + miss-islington
messages: + msg370781
2020-04-11 13:31:45furkanondersetmessages: + msg366211
2020-04-07 23:34:30furkanondersetkeywords: + patch
nosy: + furkanonder

pull_requests: + pull_request18783
stage: needs patch -> patch review
2019-04-26 18:11:23BreamoreBoysetnosy: - BreamoreBoy
2014-10-03 12:53:40brett.cannonsetmessages: + msg228325
2014-10-02 22:35:30BreamoreBoysetnosy: + BreamoreBoy

messages: + msg228273
versions: + Python 3.5, - Python 3.4
2013-11-01 03:16:53eric.snowcreate