Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f733c60

Browse files
committed
Merged revisions 61602 via svnmerge from
svn+ssh://[email protected]/python/trunk ................ r61602 | martin.v.loewis | 2008-03-19 00:22:42 -0500 (Mi, 19 Mär 2008) | 17 lines Merged revisions 61598-61599,61601 via svnmerge from svn+ssh://[email protected]/sandbox/trunk/2to3/lib2to3 ........ r61598 | david.wolever | 2008-03-18 23:58:33 -0500 (Di, 18 Mär 2008) | 1 line Added fixer for zip, and refactored a bit of code in the process. Closing #2171. ........ r61599 | david.wolever | 2008-03-19 00:04:26 -0500 (Mi, 19 Mär 2008) | 3 lines Removed a bunch of duplicate code -- it's in util now. ........ r61601 | martin.v.loewis | 2008-03-19 00:21:12 -0500 (Mi, 19 Mär 2008) | 2 lines Fix whitespace. ........ ................
1 parent ef04c44 commit f733c60

24 files changed

Lines changed: 252 additions & 177 deletions

Lib/lib2to3/fixes/basefix.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def transform(self, node, results):
8787
Args:
8888
node: the root of the parse tree that matched the fixer.
8989
results: a dict mapping symbolic names to part of the match.
90-
90+
9191
Returns:
9292
None, or a node that is a modified copy of the
9393
argument node. The node argument may also be modified in-place to
@@ -146,7 +146,7 @@ def warning(self, node, reason):
146146
def start_tree(self, tree, filename):
147147
"""Some fixers need to maintain tree-wide state.
148148
This method is called once, at the start of tree fix-up.
149-
149+
150150
tree - the root node of the tree to be processed.
151151
filename - the name of the file the tree came from.
152152
"""
@@ -158,7 +158,7 @@ def start_tree(self, tree, filename):
158158
def finish_tree(self, tree, filename):
159159
"""Some fixers need to maintain tree-wide state.
160160
This method is called once, at the conclusion of tree fix-up.
161-
161+
162162
tree - the root node of the tree to be processed.
163163
filename - the name of the file the tree came from.
164164
"""

Lib/lib2to3/fixes/fix_except.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
The following cases will be converted:
44
55
- "except E, T:" where T is a name:
6-
6+
77
except E as T:
8-
8+
99
- "except E, T:" where T is not a name, tuple or list:
10-
10+
1111
except E as t:
1212
T = t
13-
13+
1414
This is done because the target of an "except" clause must be a
1515
name.
16-
16+
1717
- "except E, T:" where T is a tuple or list literal:
18-
18+
1919
except E as t:
2020
T = t.args
2121
"""
@@ -39,7 +39,7 @@ class FixExcept(basefix.BaseFix):
3939
try_stmt< 'try' ':' suite
4040
cleanup=((except_clause ':' suite)+ ['else' ':' suite]
4141
['finally' ':' suite]
42-
| 'finally' ':' suite) >
42+
| 'finally' ':' suite) >
4343
"""
4444

4545
def transform(self, node, results):

Lib/lib2to3/fixes/fix_filter.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
"""
1515

1616
# Local imports
17-
from .. import pytree
18-
from .. import patcomp
1917
from ..pgen2 import token
2018
from . import basefix
21-
from .util import Name, Call, ListComp, attr_chain, does_tree_import
19+
from .util import Name, Call, ListComp, does_tree_import, in_special_context
2220

2321
class FixFilter(basefix.BaseFix):
2422

@@ -85,35 +83,3 @@ def transform(self, node, results):
8583
new = Call(Name("list"), [new])
8684
new.set_prefix(node.get_prefix())
8785
return new
88-
89-
P0 = """for_stmt< 'for' any 'in' node=any ':' any* >
90-
| comp_for< 'for' any 'in' node=any any* >
91-
"""
92-
p0 = patcomp.compile_pattern(P0)
93-
94-
P1 = """
95-
power<
96-
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
97-
'any' | 'all' | (any* trailer< '.' 'join' >) )
98-
trailer< '(' node=any ')' >
99-
any*
100-
>
101-
"""
102-
p1 = patcomp.compile_pattern(P1)
103-
104-
P2 = """
105-
power<
106-
'sorted'
107-
trailer< '(' arglist<node=any any*> ')' >
108-
any*
109-
>
110-
"""
111-
p2 = patcomp.compile_pattern(P2)
112-
113-
def in_special_context(node):
114-
patterns = [p0, p1, p2]
115-
for pattern, parent in zip(patterns, attr_chain(node, "parent")):
116-
results = {}
117-
if pattern.match(parent, results) and results["node"] is node:
118-
return True
119-
return False

Lib/lib2to3/fixes/fix_future.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
33
from __future__ import foo is replaced with an empty line.
44
"""
5-
# Author: Christian Heimes
5+
# Author: Christian Heimes
66

77
# Local imports
88
from . import basefix
9-
from .util import BlankLine
9+
from .util import BlankLine
1010

1111
class FixFuture(basefix.BaseFix):
1212
PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
1313

1414
def transform(self, node, results):
1515
return BlankLine()
16-

Lib/lib2to3/fixes/fix_has_key.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
m = d.has_key
1919
if m(k):
2020
...
21-
21+
2222
Only *calls* to has_key() are converted. While it is possible to
2323
convert the above to something like
24-
24+
2525
m = d.__contains__
2626
if m(k):
2727
...
28-
28+
2929
this is currently not done.
3030
"""
3131

Lib/lib2to3/fixes/fix_idioms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
type(x) is T -> isinstance(x, T)
66
type(x) != T -> not isinstance(x, T)
77
type(x) is not T -> not isinstance(x, T)
8-
8+
99
* Change "while 1:" into "while True:".
1010
1111
* Change both
@@ -19,7 +19,7 @@
1919
v = EXPR
2020
v.sort()
2121
foo(v)
22-
22+
2323
into
2424
2525
v = sorted(EXPR)

Lib/lib2to3/fixes/fix_imports.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
MAPPING = {"StringIO": ("io", ["StringIO"]),
1818
"cStringIO": ("io", ["StringIO"]),
19-
"__builtin__" : ("builtins", builtin_names),
19+
"__builtin__" : ("builtins", builtin_names),
2020
}
2121

2222

@@ -86,4 +86,4 @@ def transform(self, node, results):
8686
bare_name = bare_name[0]
8787
new_name = self.replace.get(bare_name.value)
8888
if new_name:
89-
bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))
89+
bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))

Lib/lib2to3/fixes/fix_map.py

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
"""
2121

2222
# Local imports
23-
from .. import pytree
24-
from .. import patcomp
2523
from ..pgen2 import token
2624
from . import basefix
27-
from .util import Name, Call, ListComp, attr_chain, does_tree_import
25+
from .util import Name, Call, ListComp, does_tree_import, in_special_context
2826
from ..pygram import python_symbols as syms
2927

3028
class FixMap(basefix.BaseFix):
@@ -71,7 +69,7 @@ def transform(self, node, results):
7169
# If a future map has been imported for this file, we won't
7270
# be making any modifications
7371
return
74-
72+
7573
if node.parent.type == syms.simple_stmt:
7674
self.warning(node, "You should use a for loop here")
7775
new = node.clone()
@@ -92,35 +90,3 @@ def transform(self, node, results):
9290
new = Call(Name("list"), [new])
9391
new.set_prefix(node.get_prefix())
9492
return new
95-
96-
P0 = """for_stmt< 'for' any 'in' node=any ':' any* >
97-
| comp_for< 'for' any 'in' node=any any* >
98-
"""
99-
p0 = patcomp.compile_pattern(P0)
100-
101-
P1 = """
102-
power<
103-
( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
104-
'any' | 'all' | (any* trailer< '.' 'join' >) )
105-
trailer< '(' node=any ')' >
106-
any*
107-
>
108-
"""
109-
p1 = patcomp.compile_pattern(P1)
110-
111-
P2 = """
112-
power<
113-
'sorted'
114-
trailer< '(' arglist<node=any any*> ')' >
115-
any*
116-
>
117-
"""
118-
p2 = patcomp.compile_pattern(P2)
119-
120-
def in_special_context(node):
121-
patterns = [p0, p1, p2]
122-
for pattern, parent in zip(patterns, attr_chain(node, "parent")):
123-
results = {}
124-
if pattern.match(parent, results) and results["node"] is node:
125-
return True
126-
return False

Lib/lib2to3/fixes/fix_ne.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def match(self, node):
1717
return node.type == token.NOTEQUAL and node.value == "<>"
1818

1919
def transform(self, node, results):
20-
new = pytree.Leaf(token.NOTEQUAL, "!=")
21-
new.set_prefix(node.get_prefix())
22-
return new
20+
new = pytree.Leaf(token.NOTEQUAL, "!=")
21+
new.set_prefix(node.get_prefix())
22+
return new

Lib/lib2to3/fixes/fix_next.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def transform(self, node, results):
4747
mod = results.get("mod")
4848

4949
if base:
50-
if self.shadowed_next:
51-
attr.replace(Name("__next__", prefix=attr.get_prefix()))
52-
else:
53-
base = [n.clone() for n in base]
54-
base[0].set_prefix("")
55-
node.replace(Call(Name("next", prefix=node.get_prefix()), base))
50+
if self.shadowed_next:
51+
attr.replace(Name("__next__", prefix=attr.get_prefix()))
52+
else:
53+
base = [n.clone() for n in base]
54+
base[0].set_prefix("")
55+
node.replace(Call(Name("next", prefix=node.get_prefix()), base))
5656
elif name:
5757
n = Name("__next__", prefix=name.get_prefix())
5858
name.replace(n)

0 commit comments

Comments
 (0)