Propagate exceptions in sequence::size() (#2076)

This commit is contained in:
Nicholas Musolino
2020-01-26 11:49:32 -05:00
committed by Wenzel Jakob
parent 805c5862b6
commit 02c83dba0f
3 changed files with 28 additions and 1 deletions

View File

@@ -100,6 +100,25 @@ def test_sequence():
assert cstats.move_assignments == 0
def test_sequence_length():
"""#2076: Exception raised by len(arg) should be propagated """
class BadLen(RuntimeError):
pass
class SequenceLike():
def __getitem__(self, i):
return None
def __len__(self):
raise BadLen()
with pytest.raises(BadLen):
m.sequence_length(SequenceLike())
assert m.sequence_length([1, 2, 3]) == 3
assert m.sequence_length("hello") == 5
def test_map_iterator():
sm = m.StringMap({'hi': 'bye', 'black': 'white'})
assert sm['hi'] == 'bye'