Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax the type restriction on reloaded modules #63667

Closed
ericsnowcurrently opened this issue Nov 1, 2013 · 6 comments
Closed

Relax the type restriction on reloaded modules #63667

ericsnowcurrently opened this issue Nov 1, 2013 · 6 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ericsnowcurrently
Copy link
Member

BPO 19468
Nosy @brettcannon, @ncoghlan, @ericsnowcurrently, @miss-islington, @furkanonder
PRs
  • bpo-19468: delete unnecessary instance check in importlib.reload() #19424
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-06-05.21:01:25.172>
    created_at = <Date 2013-11-01.03:16:53.747>
    labels = ['type-feature', 'library']
    title = 'Relax the type restriction on reloaded modules'
    updated_at = <Date 2020-06-05.21:01:25.171>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2020-06-05.21:01:25.171>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-06-05.21:01:25.172>
    closer = 'brett.cannon'
    components = ['Library (Lib)']
    creation = <Date 2013-11-01.03:16:53.747>
    creator = 'eric.snow'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 19468
    keywords = ['patch']
    message_count = 6.0
    messages = ['201874', '228273', '228325', '366211', '370781', '370787']
    nosy_count = 5.0
    nosy_names = ['brett.cannon', 'ncoghlan', 'eric.snow', 'miss-islington', 'furkanonder']
    pr_nums = ['19424']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue19468'
    versions = ['Python 3.5']

    @ericsnowcurrently
    Copy link
    Member Author

    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.

    @ericsnowcurrently ericsnowcurrently added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Nov 1, 2013
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Oct 2, 2014

    Can we or can't we remove the check as Eric has proposed in msg201874?

    @brettcannon
    Copy link
    Member

    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")

    @furkanonder
    Copy link
    Mannequin

    furkanonder mannequin commented Apr 11, 2020

    PR has been sent.

    @miss-islington
    Copy link
    Contributor

    New changeset fef1fae by Furkan Önder in branch 'master':
    bpo-19468: delete unnecessary instance check in importlib.reload() (GH-19424)
    fef1fae

    @brettcannon
    Copy link
    Member

    Thanks for the PR, Furkan !

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants