Skip to content

2to3: apply dict fixer. #3205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2013
Merged

Conversation

Image for: Conversation
Copy link
Member

charris commented Apr 7, 2013

In Python3 dict.items(), dict.keys(), and dict.values() are
iterators. This causes problems when a list is needed so the 2to3 fixer
explicitly constructs a list when is finds on of those functions.
However, that is usually not necessary, so a lot of the work here has
been cleaning up those places where the fix is not needed. The big
exception to that is the numpy/f2py/crackfortran.py file. The code
there makes extensive use of loops that modify the contents of the
dictionary being looped through, which raises an error. That together
with the obscurity of the code in that file made it safest to let the
dict fixer do its worst.

Closes #3050.

In Python3 `dict.items()`, `dict.keys()`, and `dict.values()` are
iterators. This causes problems when a list is needed so the 2to3 fixer
explicitly constructs a list when is finds on of those functions.
However, that is usually not necessary, so a lot of the work here has
been cleaning up those places where the fix is not needed. The big
exception to that is the `numpy/f2py/crackfortran.py` file. The code
there makes extensive use of loops that modify the contents of the
dictionary being looped through, which raises an error. That together
with the obscurity of the code in that file made it safest to let the
`dict` fixer do its worst.

Closes numpy#3050.
@@ -332,7 +332,7 @@ def _index_fields(ary, fields):
'O': 'O',
'x': 'V', # padding
}
_pep3118_native_typechars = ''.join(_pep3118_native_map.keys())
_pep3118_native_typechars = ''.join(list(_pep3118_native_map.keys()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join works on iterators

Copy link
Member

njsmith commented Apr 7, 2013

The rest look right to me.

Most of these are places where an iterator will work as well as a
list, but two fix places where `iterkeys` was introduced which is
a bug.
Copy link
Member Author

charris commented Apr 7, 2013

Thanks for the review, the PR needed it.

Copy link
Member Author

charris commented Apr 7, 2013

In the light of a new day, it also looks good to me. I'm going to put it in.

charris added a commit that referenced this pull request Apr 7, 2013
charris merged commit 1340fa6 into numpy:master Apr 7, 2013
charris deleted the 2to3-apply-dict-fixer branch April 7, 2013 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants