Interpolation bug in jupyter magic
mlucool opened this issue · 3 comments
Hi,
We came across a bug in the jupyter magic (https://github.com/joerick/pyinstrument/blob/main/pyinstrument/magic/magic.py):
>>> x = 1
>>> %pyinstrument print("$x")
1
This should print "$x" and not interpolates it. The same is true for things in {}
like %pyinstrument print("hello {len('world')}")
(%time print("hello {len('world')}")
works as expected).
While I'm not sure why this happens, I think moving to the now officially supported way to do this ast_mod would fix it (at the very least a simple test shows ast_mod does not have this bug).
Would it be ok to make a PR to move to this, knowing it only works for IPython 8.15+ (release notes)? If not, maybe we can do a version check and newer IPython versions use this and older code falls back to what we have today as most users don't seem to have run into this.
Interpolation in IPython magics can be removed by adding @no_var_expand
which is also supported in older IPython versions.
just released v4.6.1 with the fix :)
Thank you!