Skip to content

Commit

Permalink
Merge pull request #107 from brettcannon/dict-view
Browse files Browse the repository at this point in the history
Update dict_six fixer to use six.view*() functions
  • Loading branch information
takluyver committed Jan 9, 2015
2 parents af958fa + 4a04655 commit 4e6f57a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

/build
/dist
docs/_build
/docs/_build
/nose-*
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased
==========

Changes since 0.4:
* Updated the ``dict_six`` fixer to support ``six.viewitems()`` and friends.

Version 0.4
===========

Expand Down
4 changes: 2 additions & 2 deletions docs/fixers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ version of ``six`` is installed.
list(x.values())
six.itervalues(x)
six.itervalues(x)
six.viewvalues(x)
Care is taken to only call ``list()`` when not in an iterating context
(e.g. not the iterable for a ``for`` loop).
Expand Down Expand Up @@ -168,7 +168,7 @@ version of ``six`` is installed.
import six
class Foo(six.with_metaclass(Meta)):
pass
.. seealso::
:func:`six.with_metaclass`
Expand Down
4 changes: 1 addition & 3 deletions libmodernize/fixes/fix_dict_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
class FixDictSix(fix_dict.FixDict):

def transform_iter(self, method_name, node, base):
"""Call six.iteritems() and friends."""
if method_name.startswith(u'view'):
method_name = u'iter' + method_name[4:]
"""Call six.(iter|view)items() and friends."""
libmodernize.touch_import(None, u'six', node)
new_node = [n.clone() for n in base]
new_node[0].prefix = u''
Expand Down
2 changes: 1 addition & 1 deletion tests/test_fix_dict_six.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
""", """\
from __future__ import absolute_import
import six
six.iter{type}(x)
six.view{type}(x)
""")

DICT_PLAIN = ("""\
Expand Down

0 comments on commit 4e6f57a

Please sign in to comment.