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

importlib.reload() does not return the module in sys.modules #62898

Closed
ericsnowcurrently opened this issue Aug 9, 2013 · 6 comments
Closed
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@ericsnowcurrently
Copy link
Member

BPO 18698
Nosy @brettcannon, @ericsnowcurrently
Files
  • reload_replaced_module.diff
  • 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 = 'https://github.com/ericsnowcurrently'
    closed_at = <Date 2013-08-15.00:23:16.355>
    created_at = <Date 2013-08-09.23:27:18.206>
    labels = ['type-bug', 'library']
    title = 'importlib.reload() does not return the module in sys.modules'
    updated_at = <Date 2013-08-15.00:23:16.354>
    user = 'https://github.com/ericsnowcurrently'

    bugs.python.org fields:

    activity = <Date 2013-08-15.00:23:16.354>
    actor = 'eric.snow'
    assignee = 'eric.snow'
    closed = True
    closed_date = <Date 2013-08-15.00:23:16.355>
    closer = 'eric.snow'
    components = ['Library (Lib)']
    creation = <Date 2013-08-09.23:27:18.206>
    creator = 'eric.snow'
    dependencies = []
    files = ['31289']
    hgrepos = []
    issue_num = 18698
    keywords = ['patch']
    message_count = 6.0
    messages = ['194776', '194827', '195125', '195177', '195229', '195230']
    nosy_count = 3.0
    nosy_names = ['brett.cannon', 'python-dev', 'eric.snow']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue18698'
    versions = ['Python 3.3', 'Python 3.4']

    @ericsnowcurrently
    Copy link
    Member Author

    Currently reload() returns the module that loader.load_module() returns, rather than returning the one in sys.modules. This is different from what happens during normal import. I would expect reload() to return what's in sys.modules. Perhaps this got overlooked when we moved reload()? I haven't had a chance to verify, but I do recall that the switch to importlib-based import in 3.3 exposed a bug where importlib wasn't returning the module in sys.modules during normal import.

    @ericsnowcurrently ericsnowcurrently added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 9, 2013
    @brettcannon
    Copy link
    Member

    I'm sure it's an oversight.

    @ericsnowcurrently
    Copy link
    Member Author

    Yep. In 2.7 and 3.2 the PyImport_ExecCodeModuleEx() function in Python/importlib.c returns the module found in sys.modules. Here is a patch. I suppose this should be fixed in 2.7 as well. Thoughts?

    @brettcannon
    Copy link
    Member

    I think you mean in 3.3 and yes. =) Patch LGTM so I say fix in 3.3 and merge into default.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Aug 15, 2013

    New changeset e22e7268e58a by Eric Snow in branch '3.3':
    issue bpo-18698: ensure importlib.reload() returns the module out of sys.modules.
    http://hg.python.org/cpython/rev/e22e7268e58a

    New changeset 1af087712e69 by Eric Snow in branch 'default':
    Closes issue bpo-18698: ensure importlib.reload() returns the module out of sys.modules.
    http://hg.python.org/cpython/rev/1af087712e69

    @ericsnowcurrently
    Copy link
    Member Author

    oops. That commit message for 3.3 should have read "imp.reload()". :)

    @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-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants