anntzer / ipython-autoimport

Automagically import missing modules in IPython.
zlib License
58 stars 5 forks source link

There may be a bug occured when I use 'global' keyword. #10

Open coderelease opened 2 years ago

coderelease commented 2 years ago

If loaded the ipython-autoimport module, It will be found that the x variable can not be changed by function which global keyword is inside.

x = "AAAAA"
def myfunc():
  global x
  x = "BBBBB"

myfunc()

print(x)

the correct output is "BBBBB", but "AAAAA" output when use ipython autoimport.

anntzer commented 2 years ago

Good catch. This probably requires mucking with ip.global_user_ns (instead of just ip.user_ns), but I don't know much about its inner workings... A PR would be welcome.