8000 autoreload 3 has the effect of import * · Issue #14839 · ipython/ipython · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

autoreload 3 has the effect of import * #14839

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

Open
sczi opened this issue Mar 14, 2025 · 1 comment · May be fixed by #14872
Open

autoreload 3 has the effect of import * #14839

sczi opened this issue Mar 14, 2025 · 1 comment · May be fixed by #14872

Comments

@sczi
Copy link
sczi commented Mar 14, 2025

The autoreload extension is almost magical, huge thanks to whoever's worked on it. There is one behavior that I find unexpected and I think may have been unintended.

We have a file reload.py containing:

n = 5

Then in ipython we do:

%load_ext autoreload
%autoreload 3
from reload import n

now we edit and save reload.py to be:

n = 5
m = 7

Now in the ipython repl, m is also defined, even though we just imported n. In the ipython test suite for this functionality in test_autoload_newly_added_objects, it demonstrates it with from module import *. But even if we didn't import * it will effectively always behave that way, as with autoreload 3, it sets autoload_obj to True, which causes it to pass shell into superreload, where it does shell.user_ns[name] = new_obj for every new variable, even if we didn't import *, but explicitly only wanted to import n as in this example. I'm not sure if this is intended or a bug, but it seems like it has the potential to dangerously clobber existing names in cases where users didn't import *

@jaysarva jaysarva linked a pull request Apr 13, 2025 that will close this issue
@jaysarva
Copy link
Contributor

Hey @sczi thanks for catching this. I put up a PR #14872 with a minor modification to autoreload 3 so that we appropriately deal with the from X import Y and from X import Y as Z cases -- I agree that it's unlikely this is intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0