1
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'>

But for this it fails

>>> isinstance(5, typing.SupportsInt)
...
TypeError: Protocols cannot be used with isinstance().

There is a similar question but no answers

protocols-cannot-be-used-with-isinstance-why-not

R__raki__
  • 847
  • 4
  • 15
  • 30

0 Answers0