mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
Merged revisions 62263 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r62263 | martin.v.loewis | 2008-04-10 04:48:01 +0200 (Do, 10 Apr 2008) | 19 lines
Merged revisions 62080-62262 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r62092 | collin.winter | 2008-04-01 18:27:10 +0200 (Di, 01 Apr 2008) | 1 line
Add get_prev_sibling() to complement pytree's get_next_sibling().
........
r62226 | collin.winter | 2008-04-08 21:07:56 +0200 (Di, 08 Apr 2008) | 1 line
Add min() and max() to the list of special contexts that don't require adding list() calls around dict methods.
........
r62232 | collin.winter | 2008-04-09 00:12:38 +0200 (Mi, 09 Apr 2008) | 4 lines
Fix for http://bugs.python.org/issue2596
This extends fix_xrange to know about the (mostly) same special contexts as fix_dict (where a special context is something that is guaranteed to fully consume the iterable), adding list() calls where appropriate. It also special-cases "x in range(y)".
........
................
This commit is contained in:
parent
b47aace423
commit
3de92bf155
6 changed files with 119 additions and 13 deletions
|
|
@ -16,6 +16,8 @@ from os.path import dirname, pathsep
|
|||
from .. import pygram
|
||||
from .. import pytree
|
||||
from .. import refactor
|
||||
from ..fixes import util
|
||||
|
||||
|
||||
class Options:
|
||||
def __init__(self, **kwargs):
|
||||
|
|
@ -1105,8 +1107,7 @@ class Test_dict(FixerTestCase):
|
|||
self.check(b, a)
|
||||
|
||||
def test_unchanged(self):
|
||||
wrappers = ["set", "sorted", "any", "all", "tuple", "sum"]
|
||||
for wrapper in wrappers:
|
||||
for wrapper in util.consuming_calls:
|
||||
s = "s = %s(d.keys())" % wrapper
|
||||
self.unchanged(s)
|
||||
|
||||
|
|
@ -1254,26 +1255,54 @@ class Test_xrange(FixerTestCase):
|
|||
a = """x = range( 0 , 10 , 2 )"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_1(self):
|
||||
def test_single_arg(self):
|
||||
b = """x = xrange(10)"""
|
||||
a = """x = range(10)"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_2(self):
|
||||
def test_two_args(self):
|
||||
b = """x = xrange(1, 10)"""
|
||||
a = """x = range(1, 10)"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_3(self):
|
||||
def test_three_args(self):
|
||||
b = """x = xrange(0, 10, 2)"""
|
||||
a = """x = range(0, 10, 2)"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_4(self):
|
||||
def test_wrap_in_list(self):
|
||||
b = """x = range(10, 3, 9)"""
|
||||
a = """x = list(range(10, 3, 9))"""
|
||||
self.check(b, a)
|
||||
|
||||
b = """x = foo(range(10, 3, 9))"""
|
||||
a = """x = foo(list(range(10, 3, 9)))"""
|
||||
self.check(b, a)
|
||||
|
||||
b = """x = range(10, 3, 9) + [4]"""
|
||||
a = """x = list(range(10, 3, 9)) + [4]"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_xrange_in_for(self):
|
||||
b = """for i in xrange(10):\n j=i"""
|
||||
a = """for i in range(10):\n j=i"""
|
||||
self.check(b, a)
|
||||
|
||||
b = """[i for i in xrange(10)]"""
|
||||
a = """[i for i in range(10)]"""
|
||||
self.check(b, a)
|
||||
|
||||
def test_range_in_for(self):
|
||||
self.unchanged("for i in range(10): pass")
|
||||
self.unchanged("[i for i in range(10)]")
|
||||
|
||||
def test_in_contains_test(self):
|
||||
self.unchanged("x in range(10, 3, 9)")
|
||||
|
||||
def test_in_consuming_context(self):
|
||||
for call in util.consuming_calls:
|
||||
self.unchanged("a = %s(range(10))" % call)
|
||||
|
||||
class Test_raw_input(FixerTestCase):
|
||||
fixer = "raw_input"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue