ipython-autoimport icon indicating copy to clipboard operation
ipython-autoimport copied to clipboard

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

Open coderelease opened this issue 3 years ago • 1 comments

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.

coderelease avatar Apr 18 '22 05:04 coderelease

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.

anntzer avatar Apr 18 '22 17:04 anntzer