Skip to content

Commit

Permalink
Merge pull request #3242 from charris/2to3-apply-types-fixer
Browse files Browse the repository at this point in the history
2to3: Apply types fixer.
  • Loading branch information
charris committed Apr 22, 2013
2 parents 1975606 + c879ad8 commit 56e806a
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 114 deletions.
2 changes: 1 addition & 1 deletion numpy/compat/_inspect.py
Expand Up @@ -151,7 +151,7 @@ def joinseq(seq):

def strseq(object, convert, join=joinseq):
"""Recursively walk a sequence, stringifying each element."""
if type(object) in [types.ListType, types.TupleType]:
if type(object) in [list, tuple]:
return join([strseq(_o, convert, join) for _o in object])
else:
return convert(object)
Expand Down
21 changes: 11 additions & 10 deletions numpy/core/fromnumeric.py
Expand Up @@ -3,7 +3,16 @@
"""
from __future__ import division, absolute_import, print_function

__docformat__ = "restructuredtext en"
import types

from . import multiarray as mu
from . import umath as um
from . import numerictypes as nt
from .numeric import asarray, array, asanyarray, concatenate
from . import _methods

_dt_ = nt.sctype2char


# functions that are now methods
__all__ = ['take', 'reshape', 'choose', 'repeat', 'put',
Expand All @@ -16,19 +25,11 @@
'amax', 'amin',
]

from . import multiarray as mu
from . import umath as um
from . import numerictypes as nt
from .numeric import asarray, array, asanyarray, concatenate
from . import _methods
_dt_ = nt.sctype2char

import types

try:
_gentype = types.GeneratorType
except AttributeError:
_gentype = types.NoneType
_gentype = type(None)

# save away Python sum
_sum_ = sum
Expand Down
14 changes: 7 additions & 7 deletions numpy/core/records.py
Expand Up @@ -36,18 +36,18 @@
"""
from __future__ import division, absolute_import, print_function

# All of the functions allow formats to be a dtype
__all__ = ['record', 'recarray', 'format_parser']
import sys
import os

from . import numeric as sb
from .defchararray import chararray
from . import numerictypes as nt
import types
import os
import sys

from numpy.compat import isfileobj, bytes, long

# All of the functions allow formats to be a dtype
__all__ = ['record', 'recarray', 'format_parser']


ndarray = sb.ndarray

_byteorderconv = {'b':'>',
Expand Down Expand Up @@ -171,7 +171,7 @@ def _setfieldnames(self, names, titles):
attribute """

if (names):
if (type(names) in [types.ListType, types.TupleType]):
if (type(names) in [list, tuple]):
pass
elif (type(names) == str):
names = names.split(',')
Expand Down
41 changes: 20 additions & 21 deletions numpy/f2py/auxfuncs.py
Expand Up @@ -16,17 +16,16 @@
"""
from __future__ import division, absolute_import, print_function

__version__ = "$Revision: 1.65 $"[10:-1]

from . import __version__
f2py_version = __version__.version

import pprint
import sys
import types
from functools import reduce

from . import __version__
from . import cfuncs

f2py_version = __version__.version


errmess=sys.stderr.write
#outmess=sys.stdout.write
Expand Down Expand Up @@ -599,7 +598,7 @@ def gentitle(name):
return '/*%s %s %s*/'%(l*'*',name,l*'*')

def flatlist(l):
if type(l)==types.ListType:
if type(l)==list:
return reduce(lambda x,y,f=flatlist:x+f(y),l,[])
return [l]

Expand All @@ -608,9 +607,9 @@ def stripcomma(s):
return s

def replace(str,d,defaultsep=''):
if type(d)==types.ListType:
if type(d)==list:
return [replace(str, _m, defaultsep) for _m in d]
if type(str)==types.ListType:
if type(str)==list:
return [replace(_m, d, defaultsep) for _m in str]
for k in 2*list(d.keys()):
if k=='separatorsfor':
Expand All @@ -619,14 +618,14 @@ def replace(str,d,defaultsep=''):
sep=d['separatorsfor'][k]
else:
sep=defaultsep
if type(d[k])==types.ListType:
if type(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)==types.ListType:
if type(ar)==list:
for a in ar:
rd=dictappend(rd,a)
return rd
Expand All @@ -636,13 +635,13 @@ def dictappend(rd,ar):
if k in rd:
if type(rd[k])==str:
rd[k]=[rd[k]]
if type(rd[k])==types.ListType:
if type(ar[k])==types.ListType:
if type(rd[k])==list:
if type(ar[k])==list:
rd[k]=rd[k]+ar[k]
else:
rd[k].append(ar[k])
elif type(rd[k])==types.DictType:
if type(ar[k])==types.DictType:
elif type(rd[k])==dict:
if type(ar[k])==dict:
if k=='separatorsfor':
for k1 in ar[k].keys():
if k1 not in rd[k]:
Expand All @@ -655,7 +654,7 @@ def dictappend(rd,ar):

def applyrules(rules,d,var={}):
ret={}
if type(rules)==types.ListType:
if type(rules)==list:
for r in rules:
rr=applyrules(r,d,var)
ret=dictappend(ret,rr)
Expand All @@ -674,37 +673,37 @@ def applyrules(rules,d,var={}):
ret[k]=rules[k]; continue
if type(rules[k])==str:
ret[k]=replace(rules[k],d)
elif type(rules[k])==types.ListType:
elif type(rules[k])==list:
ret[k]=[]
for i in rules[k]:
ar=applyrules({k:i},d,var)
if k in ar:
ret[k].append(ar[k])
elif k[0]=='_':
continue
elif type(rules[k])==types.DictType:
elif type(rules[k])==dict:
ret[k]=[]
for k1 in rules[k].keys():
if type(k1)==types.FunctionType and k1(var):
if type(rules[k][k1])==types.ListType:
if type(rules[k][k1])==list:
for i in rules[k][k1]:
if type(i)==types.DictType:
if type(i)==dict:
res=applyrules({'supertext':i},d,var)
if 'supertext' in res:
i=res['supertext']
else: i=''
ret[k].append(replace(i,d))
else:
i=rules[k][k1]
if type(i)==types.DictType:
if type(i)==dict:
res=applyrules({'supertext':i},d)
if 'supertext' in res:
i=res['supertext']
else: i=''
ret[k].append(replace(i,d))
else:
errmess('applyrules: ignoring rule %s.\n'%repr(rules[k]))
if type(ret[k])==types.ListType:
if type(ret[k])==list:
if len(ret[k])==1:
ret[k]=ret[k][0]
if ret[k]==[]:
Expand Down
18 changes: 8 additions & 10 deletions numpy/f2py/cb_rules.py
Expand Up @@ -15,21 +15,19 @@
"""
from __future__ import division, absolute_import, print_function

__version__ = "$Revision: 1.53 $"[10:-1]
import pprint
import sys

from . import __version__
f2py_version = __version__.version
from .auxfuncs import *
from . import cfuncs

f2py_version = __version__.version

import pprint
import sys
import types
errmess=sys.stderr.write
outmess=sys.stdout.write
show=pprint.pprint

from .auxfuncs import *
from . import cfuncs

################## Rules for callback function ##############

Expand Down Expand Up @@ -484,7 +482,7 @@ def buildcallback(rout,um):
,
#endif
"""]
if type(rd['docreturn'])==types.ListType:
if type(rd['docreturn'])==list:
rd['docreturn']=stripcomma(replace('#docreturn#',{'docreturn':rd['docreturn']}))
optargs=stripcomma(replace('#docsignopt#',
{'docsignopt':rd['docsignopt']}
Expand All @@ -501,10 +499,10 @@ def buildcallback(rout,um):
rd['docstrsigns']=[]
rd['latexdocstrsigns']=[]
for k in ['docstrreq','docstropt','docstrout','docstrcbs']:
if k in rd and type(rd[k])==types.ListType:
if k in rd and type(rd[k])==list:
rd['docstrsigns']=rd['docstrsigns']+rd[k]
k='latex'+k
if k in rd and type(rd[k])==types.ListType:
if k in rd and type(rd[k])==list:
rd['latexdocstrsigns']=rd['latexdocstrsigns']+rd[k][0:1]+\
['\\begin{description}']+rd[k][1:]+\
['\\end{description}']
Expand Down
16 changes: 7 additions & 9 deletions numpy/f2py/cfuncs.py
Expand Up @@ -16,15 +16,13 @@
"""
from __future__ import division, absolute_import, print_function

__version__ = "$Revision: 1.75 $"[10:-1]
import sys
import copy

from . import __version__
f2py_version = __version__.version

import types
import sys
import copy
errmess=sys.stderr.write
f2py_version = __version__.version
errmess = sys.stderr.write

##################### Definitions ##################

Expand Down Expand Up @@ -1130,7 +1128,7 @@ def buildcfuncs():

def append_needs(need,flag=1):
global outneeds,needs
if type(need)==types.ListType:
if type(need)==list:
for n in need:
append_needs(n,flag)
elif type(need)==str:
Expand Down Expand Up @@ -1162,7 +1160,7 @@ def append_needs(need,flag=1):
if need in needs:
for nn in needs[need]:
t=append_needs(nn,0)
if type(t)==types.DictType:
if type(t)==dict:
for nnn in t.keys():
if nnn in tmp:
tmp[nnn]=tmp[nnn]+t[nnn]
Expand All @@ -1178,7 +1176,7 @@ def append_needs(need,flag=1):
if need in needs:
for nn in needs[need]:
t=append_needs(nn,flag)
if type(t)==types.DictType:
if type(t)==dict:
for nnn in t.keys():
if nnn in tmp:
tmp[nnn]=t[nnn]+tmp[nnn]
Expand Down
17 changes: 8 additions & 9 deletions numpy/f2py/crackfortran.py
Expand Up @@ -140,21 +140,20 @@
"""
from __future__ import division, absolute_import, print_function

__version__ = "$Revision: 1.177 $"[10:-1]
import platform
from . import __version__
f2py_version = __version__.version

#
import sys
import string
import fileinput
import re
import pprint
import os
import copy
import platform

from . import __version__
from .auxfuncs import *

f2py_version = __version__.version

# Global flags:
strictf77=1 # Ignore `!' comments unless line[0]=='!'
sourcecodeform='fix' # 'fix','free'
Expand Down Expand Up @@ -1523,7 +1522,7 @@ def postcrack2(block,tab='',param_map=None):
global f90modulevars
if not f90modulevars:
return block
if type(block)==types.ListType:
if type(block)==list:
ret = []
for g in block:
g = postcrack2(g,tab=tab+'\t',param_map=param_map)
Expand Down Expand Up @@ -1560,7 +1559,7 @@ def postcrack(block,args=None,tab=''):
determine expression types if in argument list
"""
global usermodules,onlyfunctions
if type(block)==types.ListType:
if type(block)==list:
gret=[]
uret=[]
for g in block:
Expand All @@ -1572,7 +1571,7 @@ def postcrack(block,args=None,tab=''):
gret.append(g)
return uret+gret
setmesstext(block)
if (not type(block)==types.DictType) and 'block' not in block:
if (not type(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':
Expand Down

0 comments on commit 56e806a

Please sign in to comment.