8000 MAINT: silence DeprecationWarning in np.safe_eval(). · numpy/numpy@132b373 · GitHub
[go: up one dir, main page]

Skip to content

Commit 132b373

Browse files
author
Ralf Gommers
committed
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.
1 parent 63cd8f3 commit 132b373

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

numpy/lib/utils.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,11 +1136,21 @@ def safe_eval(source):
11361136
SyntaxError: Unsupported source construct: compiler.ast.CallFunc
11371137
11381138
"""
1139-
# Local import to speed up numpy's import time.
1139+
# Local imports to speed up numpy's import time.
1140+
import warnings
1141+
from numpy.testing.utils import WarningManager
1142+
warn_ctx = WarningManager()
1143+
warn_ctx.__enter__()
11401144
try:
1141-
import compiler
1142-
except ImportError:
1143-
import ast as compiler
1145+
# compiler package is deprecated for 3.x, which is already solved here
1146+
warnings.simplefilter('ignore', DeprecationWarning)
1147+
try:
1148+
import compiler
1149+
except ImportError:
1150+
import ast as compiler
1151+
finally:
1152+
warn_ctx.__exit__()
1153+
11441154
walker = SafeEval()
11451155
try:
11461156
ast = compiler.parse(source, mode="eval")

0 commit comments

Comments
 (0)
0