Opened 6 years ago

Closed 5 years ago

#22529 closed defect (fixed)

reset does not restore "quit"

Reported by: Paul Zimmermann Owned by:
Priority: minor Milestone: sage-8.0
Component: user interface Keywords:
Cc: Merged in:
Authors: Steven Trogdon Reviewers: Paul Zimmermann, John Palmieri
Report Upstream: N/A Work issues:
Branch: cbd60fb (Commits, GitHub, GitLab) Commit: cbd60fbb63b3c9283dd3f284c02950a51bd99086
Dependencies: Stopgaps:

Status badges

Description

with Sage 7.5.1:

sage: reset()
sage: quit
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/localdisk/tmp/sage-7.5.1/local/lib/python2.7/site-packages/sage/all_cmdline.pyc in <module>()
----> 1 quit

NameError: name 'quit' is not defined

I believe reset() should restore exactly the initial state when starting Sage, including the quit function.

Change History (19)

comment:1 Changed 6 years ago by Matthias Köppe

Near-dup of #16704.

comment:2 Changed 6 years ago by Steven Trogdon

Will something as naive as

diff --git a/src/sage/misc/reset.pyx b/src/sage/misc/reset.pyx
index bd7c94b..21e1587 100644
--- a/src/sage/misc/reset.pyx
+++ b/src/sage/misc/reset.pyx
@@ -7,7 +7,7 @@ import sys
 
 # Exclude these from the reset command.
 # DATA, base64 -- needed by the notebook
-EXCLUDE = set(['sage_mode', '__DIR__', 'DIR', 'DATA', 'base64'])
+EXCLUDE = set(['sage_mode', '__DIR__', 'DIR', 'DATA', 'base64', 'exit', 'quit'])
 
 def reset(vars=None, attached=False):
     """

do the job, or are there other ramifications that need to be addressed?

comment:3 Changed 6 years ago by John Palmieri

I was wondering about that solution, too. It seems to work in my very superficial testing. I also wonder if we should delete 'DIR', 'DATA', and 'base64' from EXCLUDE.

comment:4 Changed 6 years ago by John Palmieri

Another idea: can we use the reset command from IPython? Type %reset at the command-line to try it. It removes sage_mode but preserves exit and quit.

comment:5 Changed 6 years ago by John Palmieri

Oops, no, %reset also kills Integer and other sage imports.

comment:6 Changed 6 years ago by John Palmieri

Maybe use %reset -s, or %reset -s -f to skip the confirmation. The command %reset_selective REGEXP will reset any names matching REGEXP:

sage: a = 3
sage: a2 = 5
sage: %whos
Variable   Type       Data/Info
-------------------------------
a          Integer    3
a2         Integer    5
sage: %reset_selective a
Once deleted, variables cannot be recovered. Proceed (y/[n])?  y
sage: %whos
Interactive namespace is empty.

sage: a = 3
sage: a2 = 5
sage: %reset_selective -f ^a$
sage: %whos
Variable   Type       Data/Info
-------------------------------
a2         Integer    5

comment:7 in reply to:  3 Changed 6 years ago by Steven Trogdon

Replying to jhpalmieri:

I was wondering about that solution, too. It seems to work in my very superficial testing. I also wonder if we should delete 'DIR', 'DATA', and 'base64' from EXCLUDE.

I don't see that these are set anywhere, even from notebook imports. What about __DIR__? I can't find it either.

Last edited 6 years ago by Steven Trogdon (previous) (diff)

comment:8 Changed 6 years ago by Steven Trogdon

Not correction above.

comment:9 Changed 6 years ago by John Palmieri

When I search for these terms in the Sage tree, I see no hits (except for this one line in reset.pyx) for __DIR__, and nothing apparently relevant for DIR, DATA, or base64. sage_mode is used in src/sage/all_cmdline.py and src/sage/all_notebook.py.

comment:10 Changed 6 years ago by Paul Zimmermann

the patch proposed in comment 2 fixes the issue for me.

Paul

comment:11 Changed 6 years ago by Steven Trogdon

Branch: u/strogdon/reset_does_not_restore__quit_

comment:12 Changed 6 years ago by Steven Trogdon

Authors: Steven Trogdon
Commit: 8725c635c3e1df92d76f7d31cd168f47c0b48a9b
Status: newneeds_review

I left __DIR__, DIR, DATA and base64 in place as I found some reference to these variables in the sagenb code. Feel free to alter.

comment:13 Changed 6 years ago by git

Commit: 8725c635c3e1df92d76f7d31cd168f47c0b48a9bcbd60fbb63b3c9283dd3f284c02950a51bd99086

Branch pushed to git repo; I updated commit sha1. New commits:

cbd60fbAdd exit and quit to EXCLUDE for trac #22529 and trac #16704

comment:14 Changed 6 years ago by Paul Zimmermann

seems fine to me. However someone should check it works in the notebook too. Paul

comment:15 Changed 5 years ago by John Palmieri

Reviewers: Paul Zimmermann, John Palmieri
Status: needs_reviewpositive_review

Looks good to me. As far as I can tell, exit and quit don't do much in the old Sage notebook. They function as they should in the Jupyter notebook. Without this branch, reset() kills them, and with this branch, it does not, and they continue to function.

comment:16 Changed 5 years ago by Steven Trogdon

So how do we deal with #16704? I don't see a dup or some other appropriate button. Perhaps positive review there too?

comment:17 in reply to:  16 Changed 5 years ago by Paul Zimmermann

Replying to strogdon:

So how do we deal with #16704? I don't see a dup or some other appropriate button. Perhaps positive review there too?

you should modify that other ticket as "resolved as duplicate".

Paul

comment:18 Changed 5 years ago by John Palmieri

Milestone: sage-7.6sage-8.0

comment:19 Changed 5 years ago by Volker Braun

Branch: u/strogdon/reset_does_not_restore__quit_cbd60fbb63b3c9283dd3f284c02950a51bd99086
Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.