Skip to content

Commit 9cc7591

Browse files
committed
Add tests for __index__
1 parent 22ccb4a commit 9cc7591

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

py/tests/range.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,24 @@ def __index__(self):
116116
assert a[b:10] == a[1:10]
117117
assert a[10:b:-1] == a[10:1:-1]
118118

119+
class NonIntegerIndex:
120+
def __index__(self):
121+
return 1.1
122+
123+
a = range(10)
124+
b = NonIntegerIndex()
125+
try:
126+
a[b]
127+
except TypeError:
128+
pass
129+
else:
130+
assert False, "TypeError not raised"
131+
132+
try:
133+
a[b:10]
134+
except TypeError:
135+
pass
136+
else:
137+
assert False, "TypeError not raised"
138+
119139
doc="finished"

0 commit comments

Comments
 (0)