[Numpy-discussion] porting NumPy to Python 3

James Watson watson.jim at gmail.com
Mon Mar 2 09:02:33 EST 2009


The following are very simple changes that allow the 2to3 program to
run on numpy without warnings.  Can someone check / commit?

numpy/linalg/lapack_lite/make_lite.py:
144c144
<         if 'BLAS' in filename
---
>         if 'BLAS' in filename:

numpy/distutils/misc_util.py:
957c957,958
<             map(data_dict[p].add,files)
---
>             for f in files:
>                 data_dict[p].add(f)
983c984,985
<             map(self.add_data_files, files)
---
>             for f in files:
>                 self.add_data_files(f)

numpy/distutils/command/build_src.py:
468c468,469
<         map(self.mkpath, target_dirs)
---
>         for td in target_dirs:
>             self.mkpath(td)
635c636,637
<         map(self.mkpath, target_dirs)
---
>         for td in target_dirs:
>             self.mkpath(td)

numpy/f2py/crackfortran.py:
686c686
<             raise 'appenddecl: Unknown variable definition key:', k
---
>             raise Exception('appenddecl: Unknown variable definition key: ' + k)
1545c1545
<         raise 'postcrack: Expected block dictionary instead of ',block
---
>         raise Exception('postcrack: Expected block dictionary instead of ' + block)

numpy/lib/function_base.py:
549c549
<         raise 'Internal Shape Error'
---
>         raise Exception('Internal Shape Error')


These changes are because
1. Python 3 no longer allows string exceptions
(http://www.python.org/dev/peps/pep-0352).  The recommended method is
to use 'except Exception',
2. map has new behaviour, and the 2to3 tool recommends changing simple
map calls to for loops, as returning the result of the map is
wasteful.


Warnings generated by 2to3 on numpy revision 6521:
RefactoringTool: Warnings/messages while refactoring:
RefactoringTool: ### In file ./numpy/distutils/misc_util.py ###
RefactoringTool: Line 957: You should use a for loop here
RefactoringTool: Line 983: You should use a for loop here
RefactoringTool: ### In file ./numpy/distutils/command/build_src.py ###
RefactoringTool: Line 468: You should use a for loop here
RefactoringTool: Line 635: You should use a for loop here
RefactoringTool: ### In file ./numpy/f2py/crackfortran.py ###
RefactoringTool: Line 686: could not convert: raise 'appenddecl:
Unknown variable definition key:', k
RefactoringTool: Python 3 does not support string exceptions
RefactoringTool: Line 1545: could not convert: raise 'postcrack:
Expected block dictionary instead of ',block
RefactoringTool: Python 3 does not support string exceptions
RefactoringTool: ### In file ./numpy/lib/function_base.py ###
RefactoringTool: Line 549: could not convert: raise 'Internal Shape Error'
RefactoringTool: Python 3 does not support string exceptions
RefactoringTool: There was 1 error:
RefactoringTool: Can't parse ./numpy/linalg/lapack_lite/make_lite.py:
ParseError: bad input: type=4, value='\n', context=('', (144, 29))



More information about the NumPy-Discussion mailing list