Opened 11 years ago

Closed 10 years ago

# Sage allows creation of variables with empty name

Reported by: Owned by: logix burcin minor sage-duplicate/invalid/wontfix symbolics sd31 schilly Volker Braun, Mariah Lenox N/A

### Description

Sage allows you to create a variable with an empty name. While this at first appears not to cause any problems, one thing it does break is reset():

sage: var(' ')
(, )
sage: whos
Variable   Type          Data/Info
----------------------------------
Expression
sage: reset()
ERROR: An unexpected error occurred while tokenizing input
The following traceback may be corrupted or invalid
The error message is: ('EOF in multi-line statement', (437, 0))

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)

/usr/local/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()

/usr/local/sage/local/lib/python2.6/site-packages/sage/misc/reset.so in sage.misc.reset.reset (sage/misc/reset.c:838)()

IndexError: string index out of range
sage: del globals()['']
sage: reset()


Sage also allows the creation of variables with other illegal names (e.g. '1a' or '1'), but for these at least reset() still works. There are two ways to fix this, the first is to disallow the creation of such variables via var(), but then all illegal cases would have to be taken care of, and it wouldn't help if you created illegal variables manually by inserting them into globals() (but I would argue that if you do this, you're on your own anyway). The second way to fix the behaviour above would be to make reset() able to delete empty variables too. This however is only viable if these variables don't break anything else, other than the case mentioned above.

### comment:1 Changed 11 years ago by leif

Perhaps one could add a warning message giving a hint in other cases, too.

From #sage-devel (IRC):

<cousteau> weird, I can't make the notebook display the same that real LaTeX
I have a variable which I called {m}:   var('{m}')   In real LaTeX, it nicely displays as an m, but in the notebook it keeps the braces
same for a variable called \mu\Omega
does the notebook just get the latex() of the variables? or does it do something else?
var('sui', latex_name="s_{u,i}")   :'( I shoild read the manual first


### comment:2 Changed 10 years ago by vbraun

• Keywords sd31 added; variable empty name removed
• Milestone changed from sage-4.7.1 to sage-duplicate/invalid/wontfix
• Status changed from new to needs_review

Fixed in the patch on #7496:

sage: var(' ')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/vbraun/opt/sage-4.7.1.alpha2/devel/sage-main/<ipython console> in <module>()

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/sage/calculus/var.so in sage.calculus.var.var (sage/calculus/var.c:687)()

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/sage/symbolic/ring.so in sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6276)()

/home/vbraun/Sage/sage/local/lib/python2.6/site-packages/sage/symbolic/ring.so in sage.symbolic.ring.SymbolicRing.var (sage/symbolic/ring.cpp:6048)()

ValueError: The name "" is not a valid Python identifier.


### comment:3 follow-up: ↓ 5 Changed 10 years ago by kcrisman

• Authors Harold Gutch deleted
• Reviewers set to Volker Braun, Mariah Lenox
• Status changed from needs_review to positive_review

Apparently this means this should be closed. Probably proper form is to let the release manager change the milestone, right, Jeroen? :)

I'm assuming that Mariah's comment on #7496 means she checked this out, so I'm putting her and Volker as reviewers for closing this.

### comment:4 Changed 10 years ago by kcrisman

It does work. This is not mentioned in the patch for #7496, though, so I'm adding a doctest there.

### comment:5 in reply to: ↑ 3 Changed 10 years ago by jdemeyer

• Resolution set to duplicate
• Status changed from positive_review to closed