diff options
author | njsmith <njs@pobox.com> | 2012-08-31 05:52:28 -0700 |
---|---|---|
committer | njsmith <njs@pobox.com> | 2012-08-31 05:52:28 -0700 |
commit | 68320a10f2e29a70a9a39110263c040aab689147 (patch) | |
tree | c6fe6f24759c62629211a201611ae3096c6a94e3 /numpy/lib/utils.py | |
parent | 5c944b9c6915264380aa2df3dcfd0629867fbe80 (diff) | |
parent | 132b373a3e50286534df73d07215c11d14d71dda (diff) | |
download | numpy-68320a10f2e29a70a9a39110263c040aab689147.tar.gz |
Merge pull request #390 from rgommers/silence-deprecation-warning
MAINT: silence DeprecationWarning in np.safe_eval().
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") |