You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 *
The text was updated successfully, but these errors were encountered:
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.
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:
Then in ipython we do:
now we edit and save reload.py to be:
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 withfrom module import *
. But even if we didn'timport *
it will effectively always behave that way, as withautoreload 3
, it setsautoload_obj
to True, which causes it to pass shell into superreload, where it doesshell.user_ns[name] = new_obj
for every new variable, even if we didn'timport *
, but explicitly only wanted to importn
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'timport *
The text was updated successfully, but these errors were encountered: