diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-26 21:31:12 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-05-02 21:13:17 -0600 |
commit | dec4f4b76ae9b2b953bcc093275aa59f93adf6fd (patch) | |
tree | 13a9a50d087f6c55a6afb942437afc99110cd6f5 /numpy/f2py/crackfortran.py | |
parent | 63a9f197d040b5479b772fd3925274fc984ffd24 (diff) | |
download | numpy-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/crackfortran.py')
-rwxr-xr-x | numpy/f2py/crackfortran.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index c86a15407..2ee8eb9a1 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -297,7 +297,7 @@ def readfortrancode(ffile,dowithline=show,istop=1): spacedigits=[' '] + [str(_m) for _m in range(10)] filepositiontext='' fin=fileinput.FileInput(ffile) - while 1: + while True: l=fin.readline() if not l: break if fin.isfirstline(): @@ -381,7 +381,7 @@ def readfortrancode(ffile,dowithline=show,istop=1): elif sourcecodeform=='free': if not cont and ext=='.pyf' and mline_mark.match(l): l = l + '\n' - while 1: + while True: lc = fin.readline() if not lc: errmess('Unexpected end of file when reading multiline\n') @@ -1167,7 +1167,7 @@ def analyzeline(m,case,line): groupcache[groupcounter]['f2pyenhancements'] = {} d = groupcache[groupcounter]['f2pyenhancements'] if m.group('this')=='usercode' and 'usercode' in d: - if type(d['usercode']) is type(''): + if isinstance(d['usercode'], str): d['usercode'] = [d['usercode']] d['usercode'].append(m.group('after')) else: @@ -1522,7 +1522,7 @@ def postcrack2(block,tab='',param_map=None): global f90modulevars if not f90modulevars: return block - if type(block)==list: + if isinstance(block, list): ret = [] for g in block: g = postcrack2(g,tab=tab+'\t',param_map=param_map) @@ -1559,7 +1559,7 @@ def postcrack(block,args=None,tab=''): determine expression types if in argument list """ global usermodules,onlyfunctions - if type(block)==list: + if isinstance(block, list): gret=[] uret=[] for g in block: @@ -1571,7 +1571,7 @@ def postcrack(block,args=None,tab=''): gret.append(g) return uret+gret setmesstext(block) - if (not type(block)==dict) and 'block' not in block: + if not isinstance(block, dict) and 'block' not in block: raise Exception('postcrack: Expected block dictionary instead of ' + \ str(block)) if 'name' in block and not block['name']=='unknown_interface': @@ -1819,12 +1819,12 @@ def getarrlen(dl,args,star='*'): except: edl.append(dl[0]) try: edl.append(myeval(dl[1],{},{})) except: edl.append(dl[1]) - if type(edl[0]) is type(0): + if isinstance(edl[0], int): p1 = 1-edl[0] if p1==0: d = str(dl[1]) elif p1<0: d = '%s-%s'%(dl[1],-p1) else: d = '%s+%s'%(dl[1],p1) - elif type(edl[1]) is type(0): + elif isinstance(edl[1], int): p1 = 1+edl[1] if p1==0: d='-(%s)' % (dl[0]) else: d='%s-(%s)' % (p1,dl[0]) @@ -2042,7 +2042,7 @@ def get_parameters(vars, global_params={}): params[n] = v #print params outmess('get_parameters: got "%s" on %s\n' % (msg,repr(v))) - if isstring(vars[n]) and type(params[n]) is type(0): + if isstring(vars[n]) and isinstance(params[n], int): params[n] = chr(params[n]) nl = n.lower() if nl!=n: @@ -2458,14 +2458,15 @@ determineexprtype_re_3 = re.compile(r'\A[+-]?[\d.]+[\d+-de.]*(_(P<name>[\w]+)|)\ determineexprtype_re_4 = re.compile(r'\A\(.*\)\Z',re.I) determineexprtype_re_5 = re.compile(r'\A(?P<name>\w+)\s*\(.*?\)\s*\Z',re.I) def _ensure_exprdict(r): - if type(r) is type(0): + if isinstance(r, int): return {'typespec':'integer'} - if type(r) is type(0.0): + if isinstance(r, float): return {'typespec':'real'} - if type(r) is type(0j): + if isinstance(r, complex): return {'typespec':'complex'} - assert type(r) is type({}),repr(r) - return r + if isinstance(r, dict): + return r + raise AssertionError(repr(r)) def determineexprtype(expr,vars,rules={}): if expr in vars: |