summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2010-01-30 11:05:48 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2010-01-30 11:05:48 (GMT)
commit16a060d1a2ddd888b2549691ebd066d06f0dcb82 (patch)
treec2a1b4065d7b2e25c89f30ee80debadb2a481f06 /Lib/lib2to3/fixes
parent93f562c4f9a751034616068468e7dc2cfd022275 (diff)
downloadcpython-16a060d1a2ddd888b2549691ebd066d06f0dcb82.zip
cpython-16a060d1a2ddd888b2549691ebd066d06f0dcb82.tar.gz
cpython-16a060d1a2ddd888b2549691ebd066d06f0dcb82.tar.bz2
Merged revisions 77846 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r77846 | martin.v.loewis | 2010-01-30 11:56:23 +0100 (Sa, 30 Jan 2010) | 13 lines Merged revisions 77419,77435 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r77419 | benjamin.peterson | 2010-01-10 21:39:48 +0100 (So, 10 Jan 2010) | 1 line enclose path in quotes to handle paths with spaces correctly #7666 ........ r77435 | alexandre.vassalotti | 2010-01-12 01:36:54 +0100 (Di, 12 Jan 2010) | 2 lines Issue #1967: Add fixer for dictionary views. ........ ................
Diffstat (limited to 'Lib/lib2to3/fixes')
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index 7c37fad..d66add8 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -11,6 +11,10 @@ d.iterkeys() -> iter(d.keys())
d.iteritems() -> iter(d.items())
d.itervalues() -> iter(d.values())
+d.viewkeys() -> d.keys()
+d.viewitems() -> d.items()
+d.viewvalues() -> d.values()
+
Except in certain very specific contexts: the iter() can be dropped
when the context is list(), sorted(), iter() or for...in; the list()
can be dropped when the context is list() or sorted() (but not iter()
@@ -39,7 +43,8 @@ class FixDict(fixer_base.BaseFix):
PATTERN = """
power< head=any+
trailer< '.' method=('keys'|'items'|'values'|
- 'iterkeys'|'iteritems'|'itervalues') >
+ 'iterkeys'|'iteritems'|'itervalues'|
+ 'viewkeys'|'viewitems'|'viewvalues') >
parens=trailer< '(' ')' >
tail=any*
>
@@ -52,7 +57,8 @@ class FixDict(fixer_base.BaseFix):
syms = self.syms
method_name = method.value
isiter = method_name.startswith("iter")
- if isiter:
+ isview = method_name.startswith("view")
+ if isiter or isview:
method_name = method_name[4:]
assert method_name in ("keys", "items", "values"), repr(method)
head = [n.clone() for n in head]
@@ -64,7 +70,7 @@ class FixDict(fixer_base.BaseFix):
prefix=method.prefix)]),
results["parens"].clone()]
new = pytree.Node(syms.power, args)
- if not special:
+ if not (special or isview):
new.prefix = ""
new = Call(Name("iter" if isiter else "list"), [new])
if tail: