fork download
  1. from typing import Protocol, runtime_checkable
  2.  
  3. @runtime_checkable
  4. class MyProtocol(Protocol):
  5. def func(): pass
  6.  
  7. class MyClass:
  8. def func(): return 1
  9.  
  10. class MyClass2:
  11. def func2(): return 1
  12.  
  13. class MyClass3:
  14. def func(): return 1
  15. def func2(): return 2
  16.  
  17.  
  18. c = MyClass()
  19. c2 = MyClass2()
  20. c3 = MyClass3()
  21. print(isinstance(type(c), MyProtocol))
  22. print(isinstance(type(c2), MyProtocol))
  23. print(isinstance(type(c3), MyProtocol))
Runtime error #stdin #stdout #stderr 0.12s 23912KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 1, in <module>
ImportError: cannot import name 'Protocol' from 'typing' (/usr/lib/python3.7/typing.py)