summaryrefslogtreecommitdiff
path: root/numpy/f2py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-09 12:44:24 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-10 16:41:13 -0600
commita6164794a63215e23fa28432d9acec4727c68d02 (patch)
treee1f1cb2da6aac69cb3410b623fcf224ec433d1a4 /numpy/f2py
parentf85bdf48aadf7b5a5f575370b589805fed190a6c (diff)
downloadnumpy-a6164794a63215e23fa28432d9acec4727c68d02.tar.gz
2to3: Apply `map` fixer.
In Python 3 `map` is an iterator while in Python 2 it returns a list. The simple fix applied by the fixer is to inclose all instances of map with `list(...)`. This is not needed in all cases, and even where appropriate list comprehensions may be preferred for their clarity. Consequently, this patch attempts to use list comprehensions where it makes sense. When the mapped function has two arguments there is another problem that can arise. In Python 3 map stops execution when the shortest argument list is exhausted, while in Python 2 it stops when the longest argument list is exhausted. Consequently the two argument case might need special care. However, we have been running Python3 converted versions of numpy since 1.5 without problems, so it is probably not something that affects us. Closes #3068
Diffstat (limited to 'numpy/f2py')
-rw-r--r--numpy/f2py/auxfuncs.py4
-rw-r--r--numpy/f2py/cfuncs.py2
-rw-r--r--numpy/f2py/common_rules.py2
-rwxr-xr-xnumpy/f2py/crackfortran.py9
-rwxr-xr-xnumpy/f2py/f2py2e.py4
-rw-r--r--numpy/f2py/f90mod_rules.py2
-rw-r--r--numpy/f2py/tests/test_array_from_pyobj.py4
7 files changed, 15 insertions, 12 deletions
diff --git a/numpy/f2py/auxfuncs.py b/numpy/f2py/auxfuncs.py
index 3f0c6a988..b7d32976a 100644
--- a/numpy/f2py/auxfuncs.py
+++ b/numpy/f2py/auxfuncs.py
@@ -609,9 +609,9 @@ def stripcomma(s):
def replace(str,d,defaultsep=''):
if type(d)==types.ListType:
- return map(lambda d,f=replace,sep=defaultsep,s=str:f(s,d,sep),d)
+ return [replace(str, _m, defaultsep) for _m in d]
if type(str)==types.ListType:
- return map(lambda s,f=replace,sep=defaultsep,d=d:f(s,d,sep),str)
+ return [replace(_m, d, defaultsep) for _m in str]
for k in 2*list(d.keys()):
if k=='separatorsfor':
continue
diff --git a/numpy/f2py/cfuncs.py b/numpy/f2py/cfuncs.py
index 755f4203b..4e61b0634 100644
--- a/numpy/f2py/cfuncs.py
+++ b/numpy/f2py/cfuncs.py
@@ -1212,7 +1212,7 @@ def get_needs():
else:
out.append(outneeds[n][0])
del outneeds[n][0]
- if saveout and (0 not in map(lambda x,y:x==y,saveout,outneeds[n])) \
+ if saveout and (0 not in map(lambda x,y:x==y, saveout, outneeds[n])) \
and outneeds[n] != []:
print(n,saveout)
errmess('get_needs: no progress in sorting needs, probably circular dependence, skipping.\n')
diff --git a/numpy/f2py/common_rules.py b/numpy/f2py/common_rules.py
index ed733a706..bfeaf4c9b 100644
--- a/numpy/f2py/common_rules.py
+++ b/numpy/f2py/common_rules.py
@@ -96,7 +96,7 @@ def buildhooks(m):
cadd('\t{\"%s\",%s,{{%s}},%s},'%(n,dm['rank'],dms,at))
cadd('\t{NULL}\n};')
inames1 = rmbadname(inames)
- inames1_tps = ','.join(map(lambda s:'char *'+s,inames1))
+ inames1_tps = ','.join(['char *'+s for s in inames1])
cadd('static void f2py_setup_%s(%s) {'%(name,inames1_tps))
cadd('\tint i_f2py=0;')
for n in inames1:
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py
index 52d198738..fe4091bcd 100755
--- a/numpy/f2py/crackfortran.py
+++ b/numpy/f2py/crackfortran.py
@@ -216,12 +216,14 @@ for n in ['int','double','float','char','short','long','void','case','while',
'type','default']:
badnames[n]=n+'_bn'
invbadnames[n+'_bn']=n
+
def rmbadname1(name):
if name in badnames:
errmess('rmbadname1: Replacing "%s" with "%s".\n'%(name,badnames[name]))
return badnames[name]
return name
-def rmbadname(names): return map(rmbadname1,names)
+
+def rmbadname(names): return [rmbadname1(_m) for _m in names]
def undo_rmbadname1(name):
if name in invbadnames:
@@ -229,7 +231,8 @@ def undo_rmbadname1(name):
%(name,invbadnames[name]))
return invbadnames[name]
return name
-def undo_rmbadname(names): return map(undo_rmbadname1,names)
+
+def undo_rmbadname(names): return [undo_rmbadname1(_m) for _m in names]
def getextension(name):
i=name.rfind('.')
@@ -292,7 +295,7 @@ def readfortrancode(ffile,dowithline=show,istop=1):
mline_mark = re.compile(r".*?'''")
if istop: dowithline('',-1)
ll,l1='',''
- spacedigits=[' ']+map(str,list(range(10)))
+ spacedigits=[' '] + [str(_m) for _m in range(10)]
filepositiontext=''
fin=fileinput.FileInput(ffile)
while 1:
diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py
index 7be960ff7..80569ecc6 100755
--- a/numpy/f2py/f2py2e.py
+++ b/numpy/f2py/f2py2e.py
@@ -324,7 +324,7 @@ def buildmodules(lst):
ret = {}
for i in range(len(mnames)):
if mnames[i] in isusedby:
- outmess('\tSkipping module "%s" which is used by %s.\n'%(mnames[i],','.join(map(lambda s:'"%s"'%s,isusedby[mnames[i]]))))
+ outmess('\tSkipping module "%s" which is used by %s.\n'%(mnames[i],','.join(['"%s"'%s for s in isusedby[mnames[i]]])))
else:
um=[]
if 'use' in modules[i]:
@@ -372,7 +372,7 @@ def run_main(comline_list):
if postlist[i]['block']=='python module' and '__user__' in postlist[i]['name']:
if postlist[i]['name'] in isusedby:
#if not quiet:
- outmess('Skipping Makefile build for module "%s" which is used by %s\n'%(postlist[i]['name'],','.join(map(lambda s:'"%s"'%s,isusedby[postlist[i]['name']]))))
+ outmess('Skipping Makefile build for module "%s" which is used by %s\n'%(postlist[i]['name'],','.join(['"%s"'%s for s in isusedby[postlist[i]['name']]])))
if 'signsfile' in options:
if options['verbose']>1:
outmess('Stopping. Edit the signature file and then run f2py on the signature file: ')
diff --git a/numpy/f2py/f90mod_rules.py b/numpy/f2py/f90mod_rules.py
index c251b2340..b68a79b64 100644
--- a/numpy/f2py/f90mod_rules.py
+++ b/numpy/f2py/f90mod_rules.py
@@ -158,7 +158,7 @@ def buildhooks(pymod):
fadd('integer flag\n')
fhooks[0]=fhooks[0]+fgetdims1
dms = eval('range(1,%s+1)'%(dm['rank']))
- fadd(' allocate(d(%s))\n'%(','.join(map(lambda i:'s(%s)'%i,dms))))
+ fadd(' allocate(d(%s))\n'%(','.join(['s(%s)'%i for i in dms])))
fhooks[0]=fhooks[0]+use_fgetdims2
fadd('end subroutine %s'%(fargs[-1]))
else:
diff --git a/numpy/f2py/tests/test_array_from_pyobj.py b/numpy/f2py/tests/test_array_from_pyobj.py
index 0621855f3..6707e8d8b 100644
--- a/numpy/f2py/tests/test_array_from_pyobj.py
+++ b/numpy/f2py/tests/test_array_from_pyobj.py
@@ -138,10 +138,10 @@ class Type(object):
self.dtypechar = typeinfo[self.NAME][0]
def cast_types(self):
- return map(self.__class__,self._cast_dict[self.NAME])
+ return [self.__class__(_m) for _m in self._cast_dict[self.NAME]]
def all_types(self):
- return map(self.__class__,self._type_names)
+ return [self.__class__(_m) for _m in self._type_names]
def smaller_types(self):
bits = typeinfo[self.NAME][3]