Skip to content

Commit

Permalink
Reproduce mismatch between pre-3.8 and post-3.8 behavior on __index__…
Browse files Browse the repository at this point in the history
… throwing TypeError
  • Loading branch information
YannickJadoul committed Jan 22, 2021
1 parent 064d671 commit caa5382
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/test_builtin_casters.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ class IndexedThought(object):
def __index__(self):
return 42

class TypeErrorThought(object):
def __index__(self):
raise TypeError

def __int__(self):
return 42

class RaisingThought(object):
def __index__(self):
raise ValueError
Expand Down Expand Up @@ -295,6 +302,8 @@ def cant_convert(v):
# "backports" this behavior.
assert convert(IndexedThought()) == 42
assert noconvert(IndexedThought()) == 42
assert convert(TypeErrorThought()) == 42
require_implicit(TypeErrorThought())
cant_convert(RaisingThought()) # no fall-back to `__int__`if `__index__` raises


Expand Down

0 comments on commit caa5382

Please sign in to comment.