diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2014-10-16 01:50:24 +0200 |
---|---|---|
committer | Julian Taylor <juliantaylor108@gmail.com> | 2014-10-16 01:50:24 +0200 |
commit | 51f0976c1ca101a01d09e26ee5dfea5360f73c63 (patch) | |
tree | d85a487a154e1a20333a5638c0953256615c40ac /numpy/lib/utils.py | |
parent | 35fad05fba626aeaf836f5bee45556a59a5ae198 (diff) | |
parent | c2c7051d926b6ce0665e53ce8dd0f522380a57d6 (diff) | |
download | numpy-51f0976c1ca101a01d09e26ee5dfea5360f73c63.tar.gz |
Merge pull request #5192 from charris/deprecate-safeeval-class
Deprecate SafeEval class
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 4a68dde18..519d0e9b9 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -4,6 +4,7 @@ import os import sys import types import re +import warnings from numpy.core.numerictypes import issubclass_, issubsctype, issubdtype from numpy.core import ndarray, ufunc, asarray @@ -1002,13 +1003,16 @@ 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`. + .. deprecated:: 1.10.0 See Also -------- safe_eval """ + def __init__(self): + warnings.warn("SafeEval is deprecated in 1.10 and will be removed.", + DeprecationWarning) def visit(self, node): cls = node.__class__ @@ -1104,21 +1108,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) #----------------------------------------------------------------------------- |