summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes/fix_dict.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/fixes/fix_dict.py')
-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: