summaryrefslogtreecommitdiff
path: root/numpy/f2py/auxfuncs.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-26 21:31:12 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-05-02 21:13:17 -0600
commitdec4f4b76ae9b2b953bcc093275aa59f93adf6fd (patch)
tree13a9a50d087f6c55a6afb942437afc99110cd6f5 /numpy/f2py/auxfuncs.py
parent63a9f197d040b5479b772fd3925274fc984ffd24 (diff)
downloadnumpy-dec4f4b76ae9b2b953bcc093275aa59f93adf6fd.tar.gz
MAINT: Apply 2to3 idioms fixer.
The idioms fixer makes the following replacements. 1) int <- bool 2) comparison or identity of types <- isinstance 3) a.sort() <- sorted(a) There were two problems that needed to be dealt with after the application of the fixer. First, the replacement of comparison or identity of types by isinstance was not always correct. The isinstance function returns true for subtypes whereas many of the places where the fixer made a substitution needed to check for exact type equality. Second, the sorted function was applied to arrays, but because it treats them as iterators and constructs a sorted list from the result, that is the wrong thing to do. Closes #3062.
Diffstat (limited to 'numpy/f2py/auxfuncs.py')
-rw-r--r--numpy/f2py/auxfuncs.py42
1 files changed, 21 insertions, 21 deletions
diff --git a/numpy/f2py/auxfuncs.py b/numpy/f2py/auxfuncs.py
index e391430f5..e835090f7 100644
--- a/numpy/f2py/auxfuncs.py
+++ b/numpy/f2py/auxfuncs.py
@@ -491,9 +491,9 @@ def getmultilineblock(rout,blockname,comment=1,counter=0):
except KeyError:
return
if not r: return
- if counter>0 and type(r) is type(''):
+ if counter > 0 and isinstance(r, str):
return
- if type(r) is type([]):
+ if isinstance(r, list):
if counter>=len(r): return
r = r[counter]
if r[:3]=="'''":
@@ -598,7 +598,7 @@ def gentitle(name):
return '/*%s %s %s*/'%(l*'*',name,l*'*')
def flatlist(l):
- if type(l)==list:
+ if isinstance(l, list):
return reduce(lambda x,y,f=flatlist:x+f(y),l,[])
return [l]
@@ -607,9 +607,9 @@ def stripcomma(s):
return s
def replace(str,d,defaultsep=''):
- if type(d)==list:
+ if isinstance(d, list):
return [replace(str, _m, defaultsep) for _m in d]
- if type(str)==list:
+ if isinstance(str, list):
return [replace(_m, d, defaultsep) for _m in str]
for k in 2*list(d.keys()):
if k=='separatorsfor':
@@ -618,14 +618,14 @@ def replace(str,d,defaultsep=''):
sep=d['separatorsfor'][k]
else:
sep=defaultsep
- if type(d[k])==list:
+ if isinstance(d[k], list):
str=str.replace('#%s#'%(k),sep.join(flatlist(d[k])))
else:
str=str.replace('#%s#'%(k),d[k])
return str
def dictappend(rd,ar):
- if type(ar)==list:
+ if isinstance(ar, list):
for a in ar:
rd=dictappend(rd,a)
return rd
@@ -633,15 +633,15 @@ def dictappend(rd,ar):
if k[0]=='_':
continue
if k in rd:
- if type(rd[k])==str:
+ if isinstance(rd[k], str):
rd[k]=[rd[k]]
- if type(rd[k])==list:
- if type(ar[k])==list:
+ if isinstance(rd[k], list):
+ if isinstance(ar[k], list):
rd[k]=rd[k]+ar[k]
else:
rd[k].append(ar[k])
- elif type(rd[k])==dict:
- if type(ar[k])==dict:
+ elif isinstance(rd[k], dict):
+ if isinstance(ar[k], dict):
if k=='separatorsfor':
for k1 in ar[k].keys():
if k1 not in rd[k]:
@@ -654,7 +654,7 @@ def dictappend(rd,ar):
def applyrules(rules,d,var={}):
ret={}
- if type(rules)==list:
+ if isinstance(rules, list):
for r in rules:
rr=applyrules(r,d,var)
ret=dictappend(ret,rr)
@@ -671,9 +671,9 @@ def applyrules(rules,d,var={}):
for k in rules.keys():
if k=='separatorsfor':
ret[k]=rules[k]; continue
- if type(rules[k])==str:
+ if isinstance(rules[k], str):
ret[k]=replace(rules[k],d)
- elif type(rules[k])==list:
+ elif isinstance(rules[k], list):
ret[k]=[]
for i in rules[k]:
ar=applyrules({k:i},d,var)
@@ -681,13 +681,13 @@ def applyrules(rules,d,var={}):
ret[k].append(ar[k])
elif k[0]=='_':
continue
- elif type(rules[k])==dict:
+ elif isinstance(rules[k], dict):
ret[k]=[]
for k1 in rules[k].keys():
- if type(k1)==types.FunctionType and k1(var):
- if type(rules[k][k1])==list:
+ if isinstance(k1, types.FunctionType) and k1(var):
+ if isinstance(rules[k][k1], list):
for i in rules[k][k1]:
- if type(i)==dict:
+ if isinstance(i, dict):
res=applyrules({'supertext':i},d,var)
if 'supertext' in res:
i=res['supertext']
@@ -695,7 +695,7 @@ def applyrules(rules,d,var={}):
ret[k].append(replace(i,d))
else:
i=rules[k][k1]
- if type(i)==dict:
+ if isinstance(i, dict):
res=applyrules({'supertext':i},d)
if 'supertext' in res:
i=res['supertext']
@@ -703,7 +703,7 @@ def applyrules(rules,d,var={}):
ret[k].append(replace(i,d))
else:
errmess('applyrules: ignoring rule %s.\n'%repr(rules[k]))
- if type(ret[k])==list:
+ if isinstance(ret[k], list):
if len(ret[k])==1:
ret[k]=ret[k][0]
if ret[k]==[]: