summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-01-05 21:43:01 +0000
committerEric Wieser <wieser.eric@gmail.com>2020-01-11 19:57:12 +0000
commitc8bdb9c7f91d12f20a3c6a27d776e2bc4a916d81 (patch)
tree963345e397c00ef098cf73abc3c6c7c8b3f6fda6 /numpy/f2py
parentc9fd0e7c1e077d3044b4f2cd419b89c8bf0544c7 (diff)
downloadnumpy-c8bdb9c7f91d12f20a3c6a27d776e2bc4a916d81.tar.gz
MAINT: Eliminate some calls to `eval`
* The instance in `_internal` is parsing tuples and integers, so `ast.literal_eval` is just fine * The instance in `crack_fortran` is just trying to lookup a function name dynamically * The instance in `f90mod_rules` is looking at the result of `capi_maps.getarrdims(...)['rank']`, which is always a string representation of an integer The f2py code is still littered with `eval`, but the remaining cases were harder to reason about.
Diffstat (limited to 'numpy/f2py')
-rwxr-xr-xnumpy/f2py/crackfortran.py11
-rw-r--r--numpy/f2py/f90mod_rules.py2
2 files changed, 7 insertions, 6 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 910120e00..31e01242e 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -3113,11 +3113,12 @@ def true_intent_list(var):
ret = []
for intent in lst:
try:
- c = eval('isintent_%s(var)' % intent)
- except NameError:
- c = 0
- if c:
- ret.append(intent)
+ f = globals()['isintent_%s' % intent]
+ except KeyError:
+ c = False
+ else:
+ if f(var):
+ ret.append(intent)
return ret
diff --git a/numpy/f2py/f90mod_rules.py b/numpy/f2py/f90mod_rules.py
index ad96591c0..f4f1bf1a9 100644
--- a/numpy/f2py/f90mod_rules.py
+++ b/numpy/f2py/f90mod_rules.py
@@ -178,7 +178,7 @@ def buildhooks(pymod):
(m['name'], undo_rmbadname1(n)))
fadd('integer flag\n')
fhooks[0] = fhooks[0] + fgetdims1
- dms = eval('range(1,%s+1)' % (dm['rank']))
+ dms = range(1, int(dm['rank']) + 1)
fadd(' allocate(d(%s))\n' %
(','.join(['s(%s)' % i for i in dms])))
fhooks[0] = fhooks[0] + use_fgetdims2