Discussion:
[Python-3000-checkins] r66120 - in python/branches/py3k: Lib/lib2to3 Lib/lib2to3/fixer_util.py Lib/lib2to3/fixes/fix_paren.py Lib/lib2to3/fixes/fix_raw_input.py Lib/lib2to3/fixes/fix_sys_exc.py Lib/lib2to3/refactor.py Lib/lib2to3/tests/test_fixers.py
benjamin.peterson
2008-09-01 19:56:06 UTC
Permalink
Author: benjamin.peterson
Date: Mon Sep 1 21:56:06 2008
New Revision: 66120

Log:
Merged revisions 66117 via svnmerge from
svn+ssh://pythondev at svn.python.org/python/trunk

................
r66117 | benjamin.peterson | 2008-09-01 12:17:22 -0500 (Mon, 01 Sep 2008) | 25 lines

Merged revisions 65887,65889,65967-65968,65981 via svnmerge from
svn+ssh://pythondev at svn.python.org/sandbox/trunk/2to3/lib2to3

........
r65887 | benjamin.peterson | 2008-08-19 17:45:04 -0500 (Tue, 19 Aug 2008) | 1 line

allow the raw_input fixer to handle calls after the raw_input (ie. raw_input().split())
........
r65889 | benjamin.peterson | 2008-08-19 18:11:03 -0500 (Tue, 19 Aug 2008) | 1 line

no need for 2.4 compatibility now
........
r65967 | benjamin.peterson | 2008-08-21 18:43:37 -0500 (Thu, 21 Aug 2008) | 1 line

allow a Call to have no arguments
........
r65968 | benjamin.peterson | 2008-08-21 18:45:13 -0500 (Thu, 21 Aug 2008) | 1 line

add a fixer for sys.exc_info etc by Jeff Balogh #2357
........
r65981 | benjamin.peterson | 2008-08-22 15:41:30 -0500 (Fri, 22 Aug 2008) | 1 line

add a fixer to add parenthese for list and gen comps #2367
........
................


Added:
python/branches/py3k/Lib/lib2to3/fixes/fix_paren.py
- copied unchanged from r66117, /python/trunk/Lib/lib2to3/fixes/fix_paren.py
python/branches/py3k/Lib/lib2to3/fixes/fix_sys_exc.py
- copied unchanged from r66117, /python/trunk/Lib/lib2to3/fixes/fix_sys_exc.py
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/lib2to3/ (props changed)
python/branches/py3k/Lib/lib2to3/fixer_util.py
python/branches/py3k/Lib/lib2to3/fixes/fix_raw_input.py
python/branches/py3k/Lib/lib2to3/refactor.py
python/branches/py3k/Lib/lib2to3/tests/test_fixers.py

Modified: python/branches/py3k/Lib/lib2to3/fixer_util.py
==============================================================================
--- python/branches/py3k/Lib/lib2to3/fixer_util.py (original)
+++ python/branches/py3k/Lib/lib2to3/fixer_util.py Mon Sep 1 21:56:06 2008
@@ -51,12 +51,12 @@

def ArgList(args, lparen=LParen(), rparen=RParen()):
"""A parenthesised argument list, used by Call()"""
- return Node(syms.trailer,
- [lparen.clone(),
- Node(syms.arglist, args),
- rparen.clone()])
+ node = Node(syms.trailer, [lparen.clone(), rparen.clone()])
+ if args:
+ node.insert_child(1, Node(syms.arglist, args))
+ return node

-def Call(func_name, args, prefix=None):
+def Call(func_name, args=None, prefix=None):
"""A function call"""
node = Node(syms.power, [func_name, ArgList(args)])
if prefix is not None:

Modified: python/branches/py3k/Lib/lib2to3/fixes/fix_raw_input.py
==============================================================================
--- python/branches/py3k/Lib/lib2to3/fixes/fix_raw_input.py (original)
+++ python/branches/py3k/Lib/lib2to3/fixes/fix_raw_input.py Mon Sep 1 21:56:06 2008
@@ -8,7 +8,7 @@
class FixRawInput(fixer_base.BaseFix):

PATTERN = """
- power< name='raw_input' trailer< '(' [any] ')' > >
+ power< name='raw_input' trailer< '(' [any] ')' > any* >
"""

def transform(self, node, results):

Modified: python/branches/py3k/Lib/lib2to3/refactor.py
==============================================================================
--- python/branches/py3k/Lib/lib2to3/refactor.py (original)
+++ python/branches/py3k/Lib/lib2to3/refactor.py Mon Sep 1 21:56:06 2008
@@ -69,13 +69,7 @@
return 2

# Set up logging handler
- if sys.version_info < (2, 4):
- hdlr = logging.StreamHandler()
- fmt = logging.Formatter('%(name)s: %(message)s')
- hdlr.setFormatter(fmt)
- logging.root.addHandler(hdlr)
- else:
- logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
+ logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)

# Initialize the refactoring tool
rt = RefactoringTool(fixer_dir, options)

Modified: python/branches/py3k/Lib/lib2to3/tests/test_fixers.py
==============================================================================
--- python/branches/py3k/Lib/lib2to3/tests/test_fixers.py (original)
+++ python/branches/py3k/Lib/lib2to3/tests/test_fixers.py Mon Sep 1 21:56:06 2008
@@ -1340,6 +1340,21 @@
a = """x = input(foo(a) + 6)"""
self.check(b, a)

+ def test_5(self):
+ b = """x = raw_input(invite).split()"""
+ a = """x = input(invite).split()"""
+ self.check(b, a)
+
+ def test_6(self):
+ b = """x = raw_input(invite) . split ()"""
+ a = """x = input(invite) . split ()"""
+ self.check(b, a)
+
+ def test_8(self):
+ b = "x = int(raw_input())"
+ a = "x = int(input())"
+ self.check(b, a)
+
class Test_funcattrs(FixerTestCase):
fixer = "funcattrs"

@@ -3330,6 +3345,98 @@
"""
self.check_both(b, a)

+class Test_sys_exc(FixerTestCase):
+ fixer = "sys_exc"
+
+ def test_0(self):
+ b = "sys.exc_type"
+ a = "sys.exc_info()[0]"
+ self.check(b, a)
+
+ def test_1(self):
+ b = "sys.exc_value"
+ a = "sys.exc_info()[1]"
+ self.check(b, a)
+
+ def test_2(self):
+ b = "sys.exc_traceback"
+ a = "sys.exc_info()[2]"
+ self.check(b, a)
+
+ def test_3(self):
+ b = "sys.exc_type # Foo"
+ a = "sys.exc_info()[0] # Foo"
+ self.check(b, a)
+
+ def test_4(self):
+ b = "sys. exc_type"
+ a = "sys. exc_info()[0]"
+ self.check(b, a)
+
+ def test_5(self):
+ b = "sys .exc_type"
+ a = "sys .exc_info()[0]"
+ self.check(b, a)
+
+
+class Test_paren(FixerTestCase):
+ fixer = "paren"
+
+ def test_0(self):
+ b = """[i for i in 1, 2 ]"""
+ a = """[i for i in (1, 2) ]"""
+ self.check(b, a)
+
+ def test_1(self):
+ b = """[i for i in 1, 2, ]"""
+ a = """[i for i in (1, 2,) ]"""
+ self.check(b, a)
+
+ def test_2(self):
+ b = """[i for i in 1, 2 ]"""
+ a = """[i for i in (1, 2) ]"""
+ self.check(b, a)
+
+ def test_3(self):
+ b = """[i for i in 1, 2 if i]"""
+ a = """[i for i in (1, 2) if i]"""
+ self.check(b, a)
+
+ def test_4(self):
+ b = """[i for i in 1, 2 ]"""
+ a = """[i for i in (1, 2) ]"""
+ self.check(b, a)
+
+ def test_5(self):
+ b = """(i for i in 1, 2)"""
+ a = """(i for i in (1, 2))"""
+ self.check(b, a)
+
+ def test_6(self):
+ b = """(i for i in 1 ,2 if i)"""
+ a = """(i for i in (1 ,2) if i)"""
+ self.check(b, a)
+
+ def test_unchanged_0(self):
+ s = """[i for i in (1, 2)]"""
+ self.unchanged(s)
+
+ def test_unchanged_1(self):
+ s = """[i for i in foo()]"""
+ self.unchanged(s)
+
+ def test_unchanged_2(self):
+ s = """[i for i in (1, 2) if nothing]"""
+ self.unchanged(s)
+
+ def test_unchanged_3(self):
+ s = """(i for i in (1, 2))"""
+ self.unchanged(s)
+
+ def test_unchanged_4(self):
+ s = """[i for i in m]"""
+ self.unchanged(s)
+

if __name__ == "__main__":
import __main__

Loading...