vars() gives me an error message

57 views
Skip to first unread message

Jim Mooney

unread,
May 1, 2017, 9:09:55 PM5/1/17
to sage-support
When I try to use vars() to see local variables I get this pink error message that goes on about "crystals" What's that about?

Dima Pasechnik

unread,
May 2, 2017, 5:37:25 AM5/2/17
to sage-support, sage-devel
Indeed, it appears that vars() is broken, and has been broken since Sage 7.5, at least.
Running

sage: vars()

ends with

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-7-a05597ed1f36> in <module>()
----> 1 vvv

/home/dima/Sage/sage-dev/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
    244             self.start_displayhook()
    245             self.write_output_prompt()
--> 246             format_dict, md_dict = self.compute_format_data(result)
    247             self.update_user_ns(result)
    248             self.fill_exec_result(result)

/home/dima/Sage/sage-dev/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    148 
    149         """
--> 150         return self.shell.display_formatter.format(result)
    151 
    152     # This can be set to True by the write_output_prompt method in a subclass

/home/dima/Sage/sage-dev/local/lib/python2.7/site-packages/sage/repl/display/formatter.pyc in format(self, obj, include, exclude)
    158         # First, use Sage rich output if there is any
    159         PLAIN_TEXT = u'text/plain'
--> 160         sage_format, sage_metadata = self.dm.displayhook(obj)
    161         assert PLAIN_TEXT in sage_format, 'plain text is always present'
    162         if sage_format.keys() != [PLAIN_TEXT]:

TypeError: 'NoneType' object is not iterable

John H Palmieri

unread,
May 2, 2017, 12:01:00 PM5/2/17
to sage-support, sage-...@googlegroups.com
I think it's a (pretty?) printing problem. For me, running

    sage: a = vars()

works without error, but then

   sage: a

gives the error. Same thing happens with locals().

--
John

Dima Pasechnik

unread,
May 2, 2017, 3:48:53 PM5/2/17
to sage-devel, sage-s...@googlegroups.com
no, it's more serious, perhaps something to do with lazy imports?

sage: v=vars()
sage: v['complete_sandpile']
<repr(<sage.misc.lazy_import.LazyImport at 0x7f2cd6528d00>) failed: AttributeError: 'module' object has no attribute 'complete_sandpile'>

(I found the value of the guilty key by running
sage: for k in v.keys(): v[k]==None;
until it breaks)

(same value on Sage 7.5 and on the latest beta)

Dima

Dima Pasechnik

unread,
May 2, 2017, 4:01:48 PM5/2/17
to sage-devel, sage-s...@googlegroups.com
In fact, complete_sandpile has been removed, but the lazy import for it is still there.
So this has to be fixed. I will open a ticket.

Dima Pasechnik

unread,
May 2, 2017, 5:33:32 PM5/2/17
to sage-devel, sage-s...@googlegroups.com
this is now #22933, ready for review.

Note that it's not a complete fix; 

sage: vars()

still fails

sage: v=vars()
sage: for k in v.keys(): print v[k]

works with the ticket branch.

John H Palmieri

unread,
May 3, 2017, 3:42:30 PM5/3/17
to sage-devel, sage-s...@googlegroups.com
See #22941 for a separate approach (independent of #22933, each ticket fixes a different problem).

  John

Jim Mooney

unread,
May 3, 2017, 8:43:05 PM5/3/17
to sage-support
I just wanted my own variables so this works. (I modified something I found on the web to delete all other values:

G = globals()
for k in G:
    if type(G[k]) == sage.symbolic.expression.Expression:
        if G[k] not in [golden_ratio, NaN, I, log2,pi,catalan,euler_gamma,twinprime, khinchin, glaisher, mertens]:
            print k
Reply all
Reply to author
Forward
Message has been deleted
0 new messages