diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2012-08-22 10:33:38 +0200 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2012-08-22 10:33:38 +0200 |
commit | 132b373a3e50286534df73d07215c11d14d71dda (patch) | |
tree | 034aea0365873f7ebaec0034bc752035e4857913 /numpy/lib/utils.py | |
parent | 63cd8f3cc751771fd27636009b8c0341a2beff45 (diff) | |
download | numpy-132b373a3e50286534df73d07215c11d14d71dda.tar.gz |
MAINT: silence DeprecationWarning in np.safe_eval().
It comes from the Python compiler package, which isn't available on Python 3.x.
We already handle that issue by instead importing the ast module.
Diffstat (limited to 'numpy/lib/utils.py')
-rw-r--r-- | numpy/lib/utils.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 924289a6a..dc6c16767 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1136,11 +1136,21 @@ def safe_eval(source): SyntaxError: Unsupported source construct: compiler.ast.CallFunc """ - # Local import to speed up numpy's import time. + # Local imports to speed up numpy's import time. + import warnings + from numpy.testing.utils import WarningManager + warn_ctx = WarningManager() + warn_ctx.__enter__() try: - import compiler - except ImportError: - import ast as compiler + # compiler package is deprecated for 3.x, which is already solved here + warnings.simplefilter('ignore', DeprecationWarning) + try: + import compiler + except ImportError: + import ast as compiler + finally: + warn_ctx.__exit__() + walker = SafeEval() try: ast = compiler.parse(source, mode="eval") |