Skip to content

Commit caa5382

Browse files
committed
Reproduce mismatch between pre-3.8 and post-3.8 behavior on __index__ throwing TypeError
1 parent 064d671 commit caa5382

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test_builtin_casters.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,13 @@ class IndexedThought(object):
268268
def __index__(self):
269269
return 42
270270

271+
class TypeErrorThought(object):
272+
def __index__(self):
273+
raise TypeError
274+
275+
def __int__(self):
276+
return 42
277+
271278
class RaisingThought(object):
272279
def __index__(self):
273280
raise ValueError
@@ -295,6 +302,8 @@ def cant_convert(v):
295302
# "backports" this behavior.
296303
assert convert(IndexedThought()) == 42
297304
assert noconvert(IndexedThought()) == 42
305+
assert convert(TypeErrorThought()) == 42
306+
require_implicit(TypeErrorThought())
298307
cant_convert(RaisingThought()) # no fall-back to `__int__`if `__index__` raises
299308

300309

0 commit comments

Comments
 (0)