List of commits:
Subject Hash Author Date (UTC)
bpo-28837: Fix lib2to3 handling of map/zip/filter calls when followed with a 'trailer', e.g. zip()[x] (#24) 93b4b47e3a720171d67f3b608de406aef462835c Stuart Berg 2017-04-06 05:19:40
Correct typo in configparser.rst (#1012) 01fa9ae5460b00bf1ced500c797176ebd3fb060d Alex Jordan 2017-04-06 02:21:30
bpo-29962: add math.remainder (#950) a0ce375e10b50f7606cb86b072fed7d8cd574fe7 Mark Dickinson 2017-04-05 17:34:27
Miscellaneous minor fixes of Misc/NEWS formatting. (#1002) a0157b5f11e621f2196af4e918b9f07688a6cd1c Serhiy Storchaka 2017-04-05 09:07:22
Update Argument Clinic generated code for bpo-29878. (#1001) bae6881b4215b2613ad08ef0dc7bed7743c2b8cc Serhiy Storchaka 2017-04-05 09:00:42
bpo-29762: More use "raise from None". (#569) 5affd23e6f42125998724787025080a24839266e Serhiy Storchaka 2017-04-05 06:37:24
bpo-29549: Fixes docstring for str.index (#256) 43ba8861e0ad044efafa46a7cc04e12ac5df640e Lisa Roach 2017-04-05 05:36:22
correct parse_qs and parse_qsl test case descriptions. (#968) 257b980b316a5206ecf6c23b958e2b7c4df4f3de Senthil Kumaran 2017-04-05 04:19:43
bpo-29649: Improve struct.pack_into() boundary error messages (#424) f78b119364b521307237a1484ba5f43f42300898 Andrew Nester 2017-04-04 10:46:25
bpo-29972: Skip tests known to fail on AIX (#979) 5de85a17029356084b96db63e04d9eb150efd9c0 Victor Stinner 2017-04-04 08:35:15
bpo-29725: DOC: add text for arraysize in sqlite3.Cursor (#947) 02e12138000da834f23719521a011fa93763384d csabella 2017-04-04 05:16:14
Remove obsolete declaration in tokenizer.h (#962) cf1958af4c762c970d1f2fa0e92577f577774c22 Jim Fasarakis-Hilliard 2017-04-03 16:18:32
Correct typo (#976) 8614b59910c0b3529891be164aee581eb729f1b3 Angus Hollands 2017-04-03 16:16:14
test_locale now ignores the DeprecationWarning (#977) 9acc6a03f1fd684fce2755b3b22f7448ad4c1dd6 Victor Stinner 2017-04-03 16:09:55
Fix misleading documentation for math.exp. (#951) 734125938d4653459593ebd28a0aec086efb1f27 Mark Dickinson 2017-04-02 15:30:04
bpo-19225: Add a table of warning names and missed exception names in C API doc (#881) e8c763128fb459c5c98194e4312f31493c0f12df cocoatomo 2017-04-02 10:45:40
bpo-29654 : Support If-Modified-Since HTTP header (browser cache) (#298) 351adda54bed3afbbf6db7725699679e68722d7d Pierre Quentel 2017-04-02 10:26:12
Minor spell fix and formatting fixes in urllib tests. (#959) efbd4ea65dbb9f87b1afeec6a760802756badee5 Senthil Kumaran 2017-04-02 06:47:35
bpo-29957: change LBYL key lookup to dict.setdefault (#938) 11fa3c7cd1b151e302d4eee0369cafbaf151c8fb Michael Selik 2017-04-02 06:02:31
bpo-26947: DOC: clarify wording on hashable in glossary (#948) 64c887ab3a400cf91bde4f0c5ef69eacc88bc5e1 csabella 2017-04-02 02:50:47
Commit 93b4b47e3a720171d67f3b608de406aef462835c - bpo-28837: Fix lib2to3 handling of map/zip/filter calls when followed with a 'trailer', e.g. zip()[x] (#24)
Author: Stuart Berg
Author date (UTC): 2017-04-06 05:19
Committer name: Benjamin Peterson
Committer date (UTC): 2017-04-06 05:19
Parent(s): 01fa9ae5460b00bf1ced500c797176ebd3fb060d
Signer:
Signing key:
Signing status: N
Tree: 0d7cc72f5bcbfb2bd3abef36e221568477968e49
File Lines added Lines deleted
Lib/lib2to3/fixes/fix_filter.py 18 3
Lib/lib2to3/fixes/fix_map.py 28 9
Lib/lib2to3/fixes/fix_zip.py 16 5
Lib/lib2to3/tests/test_fixers.py 47 9
Misc/ACKS 1 0
File Lib/lib2to3/fixes/fix_filter.py changed (mode: 100644) (index bb6718cbf7..a7a5a154f6)
... ... Python 2.6 figure it out.
15 15
16 16 # Local imports # Local imports
17 17 from .. import fixer_base from .. import fixer_base
18 from ..fixer_util import Name, Call, ListComp, in_special_context
18 from ..pytree import Node
19 from ..pygram import python_symbols as syms
20 from ..fixer_util import Name, ArgList, ListComp, in_special_context
21
19 22
20 23 class FixFilter(fixer_base.ConditionalFix): class FixFilter(fixer_base.ConditionalFix):
21 24 BM_compatible = True BM_compatible = True
 
... ... class FixFilter(fixer_base.ConditionalFix):
34 37 > >
35 38 ')' ')'
36 39 > >
40 [extra_trailers=trailer*]
37 41 > >
38 42 | |
39 43 power< power<
40 44 'filter' 'filter'
41 45 trailer< '(' arglist< none='None' ',' seq=any > ')' > trailer< '(' arglist< none='None' ',' seq=any > ')' >
46 [extra_trailers=trailer*]
42 47 > >
43 48 | |
44 49 power< power<
45 50 'filter' 'filter'
46 51 args=trailer< '(' [any] ')' > args=trailer< '(' [any] ')' >
52 [extra_trailers=trailer*]
47 53 > >
48 54 """ """
49 55
 
... ... class FixFilter(fixer_base.ConditionalFix):
53 59 if self.should_skip(node): if self.should_skip(node):
54 60 return return
55 61
62 trailers = []
63 if 'extra_trailers' in results:
64 for t in results['extra_trailers']:
65 trailers.append(t.clone())
66
56 67 if "filter_lambda" in results: if "filter_lambda" in results:
57 68 new = ListComp(results.get("fp").clone(), new = ListComp(results.get("fp").clone(),
58 69 results.get("fp").clone(), results.get("fp").clone(),
59 70 results.get("it").clone(), results.get("it").clone(),
60 71 results.get("xp").clone()) results.get("xp").clone())
72 new = Node(syms.power, [new] + trailers, prefix="")
61 73
62 74 elif "none" in results: elif "none" in results:
63 75 new = ListComp(Name("_f"), new = ListComp(Name("_f"),
64 76 Name("_f"), Name("_f"),
65 77 results["seq"].clone(), results["seq"].clone(),
66 78 Name("_f")) Name("_f"))
79 new = Node(syms.power, [new] + trailers, prefix="")
67 80
68 81 else: else:
69 82 if in_special_context(node): if in_special_context(node):
70 83 return None return None
71 new = node.clone()
84
85 args = results['args'].clone()
86 new = Node(syms.power, [Name("filter"), args], prefix="")
87 new = Node(syms.power, [Name("list"), ArgList([new])] + trailers)
72 88 new.prefix = "" new.prefix = ""
73 new = Call(Name("list"), [new])
74 89 new.prefix = node.prefix new.prefix = node.prefix
75 90 return new return new
File Lib/lib2to3/fixes/fix_map.py changed (mode: 100644) (index 9f966feede..78cf81c6f9)
... ... soon as the shortest argument is exhausted.
22 22 # Local imports # Local imports
23 23 from ..pgen2 import token from ..pgen2 import token
24 24 from .. import fixer_base from .. import fixer_base
25 from ..fixer_util import Name, Call, ListComp, in_special_context
25 from ..fixer_util import Name, ArgList, Call, ListComp, in_special_context
26 26 from ..pygram import python_symbols as syms from ..pygram import python_symbols as syms
27 from ..pytree import Node
28
27 29
28 30 class FixMap(fixer_base.ConditionalFix): class FixMap(fixer_base.ConditionalFix):
29 31 BM_compatible = True BM_compatible = True
 
... ... class FixMap(fixer_base.ConditionalFix):
32 34 map_none=power< map_none=power<
33 35 'map' 'map'
34 36 trailer< '(' arglist< 'None' ',' arg=any [','] > ')' > trailer< '(' arglist< 'None' ',' arg=any [','] > ')' >
37 [extra_trailers=trailer*]
35 38 > >
36 39 | |
37 40 map_lambda=power< map_lambda=power<
 
... ... class FixMap(fixer_base.ConditionalFix):
47 50 > >
48 51 ')' ')'
49 52 > >
53 [extra_trailers=trailer*]
50 54 > >
51 55 | |
52 56 power< power<
53 'map' trailer< '(' [arglist=any] ')' >
57 'map' args=trailer< '(' [any] ')' >
58 [extra_trailers=trailer*]
54 59 > >
55 60 """ """
56 61
 
... ... class FixMap(fixer_base.ConditionalFix):
60 65 if self.should_skip(node): if self.should_skip(node):
61 66 return return
62 67
68 trailers = []
69 if 'extra_trailers' in results:
70 for t in results['extra_trailers']:
71 trailers.append(t.clone())
72
63 73 if node.parent.type == syms.simple_stmt: if node.parent.type == syms.simple_stmt:
64 74 self.warning(node, "You should use a for loop here") self.warning(node, "You should use a for loop here")
65 75 new = node.clone() new = node.clone()
 
... ... class FixMap(fixer_base.ConditionalFix):
69 79 new = ListComp(results["xp"].clone(), new = ListComp(results["xp"].clone(),
70 80 results["fp"].clone(), results["fp"].clone(),
71 81 results["it"].clone()) results["it"].clone())
82 new = Node(syms.power, [new] + trailers, prefix="")
83
72 84 else: else:
73 85 if "map_none" in results: if "map_none" in results:
74 86 new = results["arg"].clone() new = results["arg"].clone()
87 new.prefix = ""
75 88 else: else:
76 if "arglist" in results:
77 args = results["arglist"]
78 if args.type == syms.arglist and \
79 args.children[0].type == token.NAME and \
80 args.children[0].value == "None":
89 if "args" in results:
90 args = results["args"]
91 if args.type == syms.trailer and \
92 args.children[1].type == syms.arglist and \
93 args.children[1].children[0].type == token.NAME and \
94 args.children[1].children[0].value == "None":
81 95 self.warning(node, "cannot convert map(None, ...) " self.warning(node, "cannot convert map(None, ...) "
82 96 "with multiple arguments because map() " "with multiple arguments because map() "
83 97 "now truncates to the shortest sequence") "now truncates to the shortest sequence")
84 98 return return
99
100 new = Node(syms.power, [Name("map"), args.clone()])
101 new.prefix = ""
102
85 103 if in_special_context(node): if in_special_context(node):
86 104 return None return None
87 new = node.clone()
105
106 new = Node(syms.power, [Name("list"), ArgList([new])] + trailers)
88 107 new.prefix = "" new.prefix = ""
89 new = Call(Name("list"), [new])
108
90 109 new.prefix = node.prefix new.prefix = node.prefix
91 110 return new return new
File Lib/lib2to3/fixes/fix_zip.py changed (mode: 100644) (index 8f36a94fb4..52c28df6aa)
... ... iter(<>), list(<>), tuple(<>), sorted(<>), ...join(<>), or for V in <>:.
9 9
10 10 # Local imports # Local imports
11 11 from .. import fixer_base from .. import fixer_base
12 from ..fixer_util import Name, Call, in_special_context
12 from ..pytree import Node
13 from ..pygram import python_symbols as syms
14 from ..fixer_util import Name, ArgList, in_special_context
15
13 16
14 17 class FixZip(fixer_base.ConditionalFix): class FixZip(fixer_base.ConditionalFix):
15 18
16 19 BM_compatible = True BM_compatible = True
17 20 PATTERN = """ PATTERN = """
18 power< 'zip' args=trailer< '(' [any] ')' >
21 power< 'zip' args=trailer< '(' [any] ')' > [trailers=trailer*]
19 22 > >
20 23 """ """
21 24
 
... ... class FixZip(fixer_base.ConditionalFix):
28 31 if in_special_context(node): if in_special_context(node):
29 32 return None return None
30 33
31 new = node.clone()
32 new.prefix = ""
33 new = Call(Name("list"), [new])
34 args = results['args'].clone()
35 args.prefix = ""
36
37 trailers = []
38 if 'trailers' in results:
39 trailers = [n.clone() for n in results['trailers']]
40 for n in trailers:
41 n.prefix = ""
42
43 new = Node(syms.power, [Name("zip"), args], prefix="")
44 new = Node(syms.power, [Name("list"), ArgList([new])] + trailers)
34 45 new.prefix = node.prefix new.prefix = node.prefix
35 46 return new return new
File Lib/lib2to3/tests/test_fixers.py changed (mode: 100644) (index b3f2680725..3e1a255737)
... ... class Test_filter(FixerTestCase):
2954 2954 a = """x = [x for x in range(10) if x%2 == 0]""" a = """x = [x for x in range(10) if x%2 == 0]"""
2955 2955 self.check(b, a) self.check(b, a)
2956 2956
2957 # XXX This (rare) case is not supported
2958 ## b = """x = filter(f, 'abc')[0]"""
2959 ## a = """x = list(filter(f, 'abc'))[0]"""
2960 ## self.check(b, a)
2957 def test_filter_trailers(self):
2958 b = """x = filter(None, 'abc')[0]"""
2959 a = """x = [_f for _f in 'abc' if _f][0]"""
2960 self.check(b, a)
2961
2962 b = """x = len(filter(f, 'abc')[0])"""
2963 a = """x = len(list(filter(f, 'abc'))[0])"""
2964 self.check(b, a)
2965
2966 b = """x = filter(lambda x: x%2 == 0, range(10))[0]"""
2967 a = """x = [x for x in range(10) if x%2 == 0][0]"""
2968 self.check(b, a)
2969
2970 # Note the parens around x
2971 b = """x = filter(lambda (x): x%2 == 0, range(10))[0]"""
2972 a = """x = [x for x in range(10) if x%2 == 0][0]"""
2973 self.check(b, a)
2961 2974
2962 2975 def test_filter_nochange(self): def test_filter_nochange(self):
2963 2976 a = """b.join(filter(f, 'abc'))""" a = """b.join(filter(f, 'abc'))"""
 
... ... class Test_map(FixerTestCase):
3022 3035 a = """x = list(map( f, 'abc' ))""" a = """x = list(map( f, 'abc' ))"""
3023 3036 self.check(b, a) self.check(b, a)
3024 3037
3038 def test_map_trailers(self):
3039 b = """x = map(f, 'abc')[0]"""
3040 a = """x = list(map(f, 'abc'))[0]"""
3041 self.check(b, a)
3042
3043 b = """x = map(None, l)[0]"""
3044 a = """x = list(l)[0]"""
3045 self.check(b, a)
3046
3047 b = """x = map(lambda x:x, l)[0]"""
3048 a = """x = [x for x in l][0]"""
3049 self.check(b, a)
3050
3051 b = """x = map(f, 'abc')[0][1]"""
3052 a = """x = list(map(f, 'abc'))[0][1]"""
3053 self.check(b, a)
3054
3025 3055 def test_trailing_comment(self): def test_trailing_comment(self):
3026 3056 b = """x = map(f, 'abc') # foo""" b = """x = map(f, 'abc') # foo"""
3027 3057 a = """x = list(map(f, 'abc')) # foo""" a = """x = list(map(f, 'abc')) # foo"""
 
... ... class Test_map(FixerTestCase):
3066 3096 """ """
3067 3097 self.warns(b, a, "You should use a for loop here") self.warns(b, a, "You should use a for loop here")
3068 3098
3069 # XXX This (rare) case is not supported
3070 ## b = """x = map(f, 'abc')[0]"""
3071 ## a = """x = list(map(f, 'abc'))[0]"""
3072 ## self.check(b, a)
3073
3074 3099 def test_map_nochange(self): def test_map_nochange(self):
3075 3100 a = """b.join(map(f, 'abc'))""" a = """b.join(map(f, 'abc'))"""
3076 3101 self.unchanged(a) self.unchanged(a)
 
... ... class Test_zip(FixerTestCase):
3130 3155 super(Test_zip, self).check(b, a) super(Test_zip, self).check(b, a)
3131 3156
3132 3157 def test_zip_basic(self): def test_zip_basic(self):
3158 b = """x = zip()"""
3159 a = """x = list(zip())"""
3160 self.check(b, a)
3161
3133 3162 b = """x = zip(a, b, c)""" b = """x = zip(a, b, c)"""
3134 3163 a = """x = list(zip(a, b, c))""" a = """x = list(zip(a, b, c))"""
3135 3164 self.check(b, a) self.check(b, a)
 
... ... class Test_zip(FixerTestCase):
3138 3167 a = """x = len(list(zip(a, b)))""" a = """x = len(list(zip(a, b)))"""
3139 3168 self.check(b, a) self.check(b, a)
3140 3169
3170 def test_zip_trailers(self):
3171 b = """x = zip(a, b, c)[0]"""
3172 a = """x = list(zip(a, b, c))[0]"""
3173 self.check(b, a)
3174
3175 b = """x = zip(a, b, c)[0][1]"""
3176 a = """x = list(zip(a, b, c))[0][1]"""
3177 self.check(b, a)
3178
3141 3179 def test_zip_nochange(self): def test_zip_nochange(self):
3142 3180 a = """b.join(zip(a, b))""" a = """b.join(zip(a, b))"""
3143 3181 self.unchanged(a) self.unchanged(a)
File Misc/ACKS changed (mode: 100644) (index f761ba33dd..70678c3c2f)
... ... Andrew Bennetts
128 128 Andy Bensky Andy Bensky
129 129 Bennett Benson Bennett Benson
130 130 Ezra Berch Ezra Berch
131 Stuart Berg
131 132 Michel Van den Bergh Michel Van den Bergh
132 133 Julian Berman Julian Berman
133 134 Brice Berna Brice Berna
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/benf_wspdigital/cpython

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/benf_wspdigital/cpython

Clone this repository using git:
git clone git://git.rocketgit.com/user/benf_wspdigital/cpython

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main