Skip to content
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

Interpolation bug in jupyter magic #277

Closed
mlucool opened this issue Oct 27, 2023 · 3 comments · Fixed by #278
Closed

Interpolation bug in jupyter magic #277

mlucool opened this issue Oct 27, 2023 · 3 comments · Fixed by #278

Comments

@mlucool
Copy link
Contributor

mlucool commented Oct 27, 2023

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.

@krassowski
Copy link
Contributor

Interpolation in IPython magics can be removed by adding @no_var_expand which is also supported in older IPython versions.

@joerick
Copy link
Owner

joerick commented Nov 8, 2023

just released v4.6.1 with the fix :)

@krassowski
Copy link
Contributor

Thank you!

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.

3 participants