IPython magic commands, automagic, and conflicts

23 views
Skip to first unread message

John H Palmieri

unread,
Jul 10, 2023, 5:22:01 PM7/10/23
to sage-devel
IPython comes with various "magic" commands, for example "%ls" which runs the shell command "ls". The default mode in Sage is "Automagic is ON, % prefix IS NOT needed for line magics." This means that running "ls" within Sage does the same thing as running "%ls". So far so good. There are, though, some magic commands that don't work like this, because we have defined other functions that shadow them. These include:

- All interfaces, as far as I can tell. Something like "%Lisp" invokes an IPython magic command, and it behaves differently than just "Lisp". I personally don't use these interfaces, so I have no opinion about what to do here.

- %attach vs. attach. Similar but perhaps not identical? The help strings are certainly different.
- %colors vs. colors. Very different: the former lets you switch color schemes in the command-line interface. The latter is a "dict-like collection of colors"
- %display vs. display. Very different: the former lets you "switch between simple display and ASCII art". The latter displays "a Python object in all frontends."
- %edit vs. edit. Similar but not identical. The former opens "an editor and execute[s] the resulting code." The latter opens "source code of ``obj`` in editor of your choice." Note that "%ed" and "ed" are both aliases for "%edit".
- %reset vs. reset. Similar but perhaps not identical? The help strings are certainly different. %reset takes some arguments, reset does not. Compare to "%reset_selective", which is the same as "reset_selective".
- %timeit vs. timeit. Similar but not identical.
- Also %load, %read_data, %save, maybe some others.

There is potential for confusion if users switch back and forth between IPython and Sage. There is also potential for confusion when two commands are similar but not identical. Is it worth addressing any of these? We could, for example, rename the Sage versions.

(See also https://github.com/sagemath/sage/issues/30661 for a somewhat related issue.)

--
John

Reply all
Reply to author
Forward
0 new messages