Skip to content

Commit 2673c8b

Browse files
committed
Don't sort in sage.misc.session.show_identifiers()
There's no need to do it. Moreover, dictionaries in python keep insertion order, so we don't need to sort for testing either. Note that in the test sage: a = 10 sage: factor = 20 sage: show_identifiers() ['factor', 'a'] factor is indeed inserted first at sagemath startup (as a function)
1 parent afaf7d5 commit 2673c8b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/sage/misc/session.pyx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This saves a dictionary with ``w`` as one of the keys::
2727
2828
sage: z = load(os.path.join(d.name, 'session'))
2929
sage: list(z)
30-
['d', 'w']
30+
['w', 'd']
3131
sage: z['w']
3232
2/3
3333
@@ -200,7 +200,7 @@ def show_identifiers(hidden=False):
200200
sage: a = 10
201201
sage: factor = 20
202202
sage: show_identifiers()
203-
['a', 'factor']
203+
['factor', 'a']
204204
205205
To get the actual value of a variable from the list, use the
206206
:func:`globals()` function.::
@@ -214,18 +214,21 @@ def show_identifiers(hidden=False):
214214
215215
sage: _hello = 10
216216
sage: show_identifiers()
217-
['a', 'factor']
217+
['factor', 'a']
218218
sage: '_hello' in show_identifiers(hidden=True)
219219
True
220220
221221
Many of the hidden variables are part of the IPython command history, at
222222
least in command line mode.::
223223
224224
sage: show_identifiers(hidden=True) # random output
225-
['__', '_i', '_6', '_4', '_3', '_1', '_ii', '__doc__', '__builtins__', '___', '_9', '__name__', '_', 'a', '_i12', '_i14', 'factor', '__file__', '_hello', '_i13', '_i11', '_i10', '_i15', '_i5', '_13', '_10', '_iii', '_i9', '_i8', '_i7', '_i6', '_i4', '_i3', '_i2', '_i1', '_init_cmdline', '_14']
225+
['__builtin__', '_ih', '_oh', '_dh', 'exit', 'quit', '_', '__', '___',
226+
'_i', '_ii', '_iii', '_i1', 'factor', '_i2', '_2', '_i3', 'a', '_i4',
227+
'_i5', '_5', '_i6', '_6', '_i7', '_hello', '_i8', '_8', '_i9', '_9',
228+
'_i10']
226229
"""
227230
state = caller_locals()
228-
return sorted([x for x, v in state.items() if _is_new_var(x, v, hidden)])
231+
return [x for x, v in state.items() if _is_new_var(x, v, hidden)]
229232

230233

231234
def save_session(name='sage_session', verbose=False):
@@ -288,17 +291,15 @@ def save_session(name='sage_session', verbose=False):
288291
sage: f = lambda x : x^2
289292
sage: save_session(tmp_f)
290293
sage: save_session(tmp_f, verbose=True)
291-
Saving...
292-
Not saving f: f is a function or method
293294
...
295+
Not saving f: f is a function or method
294296
295297
Something similar happens for cython-defined functions::
296298
297299
sage: g = cython_lambda('double x', 'x*x + 1.5')
298300
sage: save_session(tmp_f, verbose=True)
299-
Saving...
300-
Not saving g: g is a cython function or method
301301
...
302+
Not saving g: g is a cython function or method
302303
303304
And the same for a lazy import::
304305
@@ -307,7 +308,6 @@ def save_session(name='sage_session', verbose=False):
307308
sage: save_session(tmp_f, verbose=True)
308309
...
309310
Not saving lazy_ZZ: lazy_ZZ is a lazy import
310-
...
311311
"""
312312
state = caller_locals()
313313
# This dict D will contain the session -- as a dict -- that we will save to disk.

0 commit comments

Comments
 (0)