mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
adding passing test. testing for g(*Nothing()) where Nothing is a user-defined iterator.
This commit is contained in:
parent
0bc9c919e8
commit
8036c83630
2 changed files with 26 additions and 0 deletions
|
@ -17,6 +17,7 @@ TypeError: g() takes at least 1 argument (0 given)
|
||||||
1 (2, 3) {}
|
1 (2, 3) {}
|
||||||
1 (2, 3, 4, 5) {}
|
1 (2, 3, 4, 5) {}
|
||||||
0 (1, 2) {}
|
0 (1, 2) {}
|
||||||
|
0 (1, 2, 3) {}
|
||||||
1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4}
|
1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4}
|
||||||
{'a': 1, 'b': 2, 'c': 3}
|
{'a': 1, 'b': 2, 'c': 3}
|
||||||
{'a': 1, 'b': 2, 'c': 3}
|
{'a': 1, 'b': 2, 'c': 3}
|
||||||
|
|
|
@ -86,6 +86,31 @@ class Nothing:
|
||||||
raise IndexError, i
|
raise IndexError, i
|
||||||
g(*Nothing())
|
g(*Nothing())
|
||||||
|
|
||||||
|
class Nothing:
|
||||||
|
def __init__(self):
|
||||||
|
self.c = 0
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
try:
|
||||||
|
g(*Nothing())
|
||||||
|
except TypeError, attr:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
print "should raise TypeError"
|
||||||
|
|
||||||
|
class Nothing:
|
||||||
|
def __init__(self):
|
||||||
|
self.c = 0
|
||||||
|
def __iter__(self):
|
||||||
|
return self
|
||||||
|
def next(self):
|
||||||
|
if self.c == 4:
|
||||||
|
raise StopIteration
|
||||||
|
c = self.c
|
||||||
|
self.c += 1
|
||||||
|
return c
|
||||||
|
g(*Nothing())
|
||||||
|
|
||||||
# make sure the function call doesn't stomp on the dictionary?
|
# make sure the function call doesn't stomp on the dictionary?
|
||||||
d = {'a': 1, 'b': 2, 'c': 3}
|
d = {'a': 1, 'b': 2, 'c': 3}
|
||||||
d2 = d.copy()
|
d2 = d.copy()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue