Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(13)

Side by Side Diff: Lib/test/test_extcall.py

Issue 4806: Function calls taking a generator as star argument can mask TypeErrors in the generator
Patch Set: Created 4 years, 4 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Misc/NEWS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 """Doctest for method/function calls. 3 """Doctest for method/function calls.
4 4
5 We're going the use these types for extra testing 5 We're going the use these types for extra testing
6 6
7 >>> from UserList import UserList 7 >>> from UserList import UserList
8 >>> from UserDict import UserDict 8 >>> from UserDict import UserDict
9 9
10 We're defining four helper functions 10 We're defining four helper functions
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 >>> g(1, 2, 3) 86 >>> g(1, 2, 3)
87 1 (2, 3) {} 87 1 (2, 3) {}
88 >>> g(1, 2, 3, *(4, 5)) 88 >>> g(1, 2, 3, *(4, 5))
89 1 (2, 3, 4, 5) {} 89 1 (2, 3, 4, 5) {}
90 90
91 >>> class Nothing: pass 91 >>> class Nothing: pass
92 ... 92 ...
93 >>> g(*Nothing()) 93 >>> g(*Nothing())
94 Traceback (most recent call last): 94 Traceback (most recent call last):
95 ... 95 ...
96 TypeError: g() argument after * must be a sequence, not instance 96 TypeError: g() argument after * must be an iterable, not instance
97 97
98 >>> class Nothing: 98 >>> class Nothing:
99 ... def __len__(self): return 5 99 ... def __len__(self): return 5
100 ... 100 ...
101 101
102 >>> g(*Nothing()) 102 >>> g(*Nothing())
103 Traceback (most recent call last): 103 Traceback (most recent call last):
104 ... 104 ...
105 TypeError: g() argument after * must be a sequence, not instance 105 TypeError: g() argument after * must be an iterable, not instance
106 106
107 >>> class Nothing(): 107 >>> class Nothing():
108 ... def __len__(self): return 5 108 ... def __len__(self): return 5
109 ... def __getitem__(self, i): 109 ... def __getitem__(self, i):
110 ... if i<3: return i 110 ... if i<3: return i
111 ... else: raise IndexError(i) 111 ... else: raise IndexError(i)
112 ... 112 ...
113 113
114 >>> g(*Nothing()) 114 >>> g(*Nothing())
115 0 (1, 2) {} 115 0 (1, 2) {}
116 116
117 >>> class Nothing: 117 >>> class Nothing:
118 ... def __init__(self): self.c = 0 118 ... def __init__(self): self.c = 0
119 ... def __iter__(self): return self 119 ... def __iter__(self): return self
120 ... def next(self): 120 ... def next(self):
121 ... if self.c == 4: 121 ... if self.c == 4:
122 ... raise StopIteration 122 ... raise StopIteration
123 ... c = self.c 123 ... c = self.c
124 ... self.c += 1 124 ... self.c += 1
125 ... return c 125 ... return c
126 ... 126 ...
127 127
128 >>> g(*Nothing()) 128 >>> g(*Nothing())
129 0 (1, 2, 3) {} 129 0 (1, 2, 3) {}
130
131 Check for issue #4806: Does a TypeError in a generator get propagated with the
132 right error message?
133
134 >>> def broken(): raise TypeError("myerror")
135 ...
136
137 >>> g(*(broken() for i in range(1)))
138 Traceback (most recent call last):
139 ...
140 TypeError: myerror
130 141
131 Make sure that the function doesn't stomp the dictionary 142 Make sure that the function doesn't stomp the dictionary
132 143
133 >>> d = {'a': 1, 'b': 2, 'c': 3} 144 >>> d = {'a': 1, 'b': 2, 'c': 3}
134 >>> d2 = d.copy() 145 >>> d2 = d.copy()
135 >>> g(1, d=4, **d) 146 >>> g(1, d=4, **d)
136 1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4} 147 1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4}
137 >>> d == d2 148 >>> d == d2
138 True 149 True
139 150
(...skipping 20 matching lines...) Expand all
160 TypeError: f() keywords must be strings 171 TypeError: f() keywords must be strings
161 172
162 >>> h(**{'e': 2}) 173 >>> h(**{'e': 2})
163 Traceback (most recent call last): 174 Traceback (most recent call last):
164 ... 175 ...
165 TypeError: h() got an unexpected keyword argument 'e' 176 TypeError: h() got an unexpected keyword argument 'e'
166 177
167 >>> h(*h) 178 >>> h(*h)
168 Traceback (most recent call last): 179 Traceback (most recent call last):
169 ... 180 ...
170 TypeError: h() argument after * must be a sequence, not function 181 TypeError: h() argument after * must be an iterable, not function
171 182
172 >>> dir(*h) 183 >>> dir(*h)
173 Traceback (most recent call last): 184 Traceback (most recent call last):
174 ... 185 ...
175 TypeError: dir() argument after * must be a sequence, not function 186 TypeError: dir() argument after * must be an iterable, not function
176 187
177 >>> None(*h) 188 >>> None(*h)
178 Traceback (most recent call last): 189 Traceback (most recent call last):
179 ... 190 ...
180 TypeError: NoneType object argument after * must be a sequence, \ 191 TypeError: NoneType object argument after * must be an iterable, \
181 not function 192 not function
182 193
183 >>> h(**h) 194 >>> h(**h)
184 Traceback (most recent call last): 195 Traceback (most recent call last):
185 ... 196 ...
186 TypeError: h() argument after ** must be a mapping, not function 197 TypeError: h() argument after ** must be a mapping, not function
187 198
188 >>> dir(**h) 199 >>> dir(**h)
189 Traceback (most recent call last): 200 Traceback (most recent call last):
190 ... 201 ...
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 else: 321 else:
311 self.fail("duplicate arguments didn't raise") 322 self.fail("duplicate arguments didn't raise")
312 323
313 324
314 def test_main(): 325 def test_main():
315 test_support.run_doctest(sys.modules[__name__], True) 326 test_support.run_doctest(sys.modules[__name__], True)
316 test_support.run_unittest(ExtCallTest) 327 test_support.run_unittest(ExtCallTest)
317 328
318 if __name__ == '__main__': 329 if __name__ == '__main__':
319 test_main() 330 test_main()
OLDNEW
« no previous file with comments | « no previous file | Misc/NEWS » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+