from typing import SupportsInt
class C1():
def __int__(self) -> int:
return 42
class C2(C1):
pass
>>>c = C2()
>>>print(int(c))
42
>>>print(isinstance(c, C1))
True
>>> type(typing.SupportsInt)
<class 'typing._ProtocolMeta'>
但为此它失败了
>>> isinstance(5, typing.SupportsInt)
...
TypeError: Protocols cannot be used with isinstance().
有一个类似的问题,但没有答案