diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2014-10-12 09:45:20 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2014-10-15 16:16:20 -0600 |
commit | 727655193aa9b4d4068650a3f8a9b49a6a2e0cb4 (patch) | |
tree | 58b6425798ac5848be6b762325fbbe2881923c4e /numpy/lib/utils.py | |
parent | 35fad05fba626aeaf836f5bee45556a59a5ae198 (diff) | |
download | numpy-727655193aa9b4d4068650a3f8a9b49a6a2e0cb4.tar.gz |
MAINT: Use ast.literal_eval in safe_eval.
This does what is needed now that the compiler module is no longer
used.
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 4a68dde18..267653025 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1002,8 +1002,6 @@ class SafeEval(object): This includes strings with lists, dicts and tuples using the abstract syntax tree created by ``compiler.parse``. - For an example of usage, see `safe_eval`. - See Also -------- safe_eval @@ -1104,21 +1102,11 @@ def safe_eval(source): >>> np.safe_eval('open("/home/user/.ssh/id_dsa").read()') Traceback (most recent call last): ... - SyntaxError: Unsupported source construct: <class '_ast.Call'> + SyntaxError: Unsupported source construct: compiler.ast.CallFunc """ - # Local imports to speed up numpy's import time. - import warnings + # Local import to speed up numpy's import time. import ast - walker = SafeEval() - try: - res = ast.parse(source, mode="eval") - except SyntaxError: - raise - try: - return walker.visit(res) - except SyntaxError: - raise - + return ast.literal_eval(source) #----------------------------------------------------------------------------- |