Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
src/sage/symbolic/ring.pyx (isidentifier): Remove py2-only code, use …
Browse files Browse the repository at this point in the history
…of deprecated parser module
  • Loading branch information
Matthias Koeppe committed Sep 18, 2020
1 parent f3cb571 commit e16ded2
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/sage/symbolic/ring.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ from sage.rings.all import RR, CC, ZZ

import keyword
import operator
import parser

# Do not allow any of these keywords as identifiers for symbolic variables
KEYWORDS = set(keyword.kwlist).union(['exec', 'print', 'None', 'True',
Expand Down Expand Up @@ -1380,7 +1379,7 @@ def isidentifier(x):
Boolean. Whether the string ``x`` can be used as a variable name.
This function should return ``False`` for keywords, so we can not
just use the ``isidentifier`` method of strings (in Python 3),
just use the ``isidentifier`` method of strings,
because, for example, it returns ``True`` for "def" and for "None".
EXAMPLES::
Expand Down Expand Up @@ -1409,15 +1408,4 @@ def isidentifier(x):
"""
if x in KEYWORDS:
return False
try:
if not x.isidentifier(): # py3
return False
except AttributeError:
pass # py2

try:
code = parser.expr(x).compile()
except (MemoryError, OverflowError, SyntaxError,
SystemError, parser.ParserError):
return False
return len(code.co_names) == 1 and code.co_names[0] == x
return x.isidentifier()

0 comments on commit e16ded2

Please sign in to comment.