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

Previously defined variables like _3 are silently overwritten #12290

Open
phaunt opened this issue May 6, 2020 · 0 comments
Open

Previously defined variables like _3 are silently overwritten #12290

phaunt opened this issue May 6, 2020 · 0 comments

Comments

@phaunt
Copy link

phaunt commented May 6, 2020

I was working on a little program in the IPython shell (invoked like ipython3 -i example.py) and got stumped for a while when a variable named _3 defined in example.py produced unexpected behaviour, but not immediately.

It took a while before I noticed that this problem didn't occur in the regular python shell, and even then the penny didn't drop immediately, because I wasn't yet familiar with the _n automatic variables for the output cache – I freely admit I'm still something of an IPython newbie.

Possible suggestions to prevent this kind of surprise:

  • present the user with a warning when assigning to a variable that may be silently overwritten in the future
  • or even an info or debug notice instead of a warning (e.g. when the user passes the --debug command-line flag to ipython)
  • or perhaps present this warning at the point that a previously assigned variable gets overwritten
  • or more fancily: make it configurable whether automatic variables are used at all (for the case of _3, setting --cache-size=0 would have worked, but this still doesn't prevent the likes of _i3 getting overwritten)
  • or yet more fancily: make it configurable whether automatic variables are allowed to overwrite previously set values

Finally, I suggest mentioning _4 in the %quickref, like _i4 already is. It's a strange omission at this point. For symmetry,

_oh              : Output history

could be replaced by

_4, _oh[2:5]     : Output history line 4, lines 2-4
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

No branches or pull requests

1 participant