Return True if the given type is a Protocol. Example:: >>> from typing import Protocol, is_protocol >>> class P(Protocol): ... def a(self) -> str: ... ... b: int >>> is_protocol(P) True >>> is_protocol(int) False
(tp: type, /)
| 3836 | |
| 3837 | |
| 3838 | def is_protocol(tp: type, /) -> bool: |
| 3839 | """Return True if the given type is a Protocol. |
| 3840 | |
| 3841 | Example:: |
| 3842 | |
| 3843 | >>> from typing import Protocol, is_protocol |
| 3844 | >>> class P(Protocol): |
| 3845 | ... def a(self) -> str: ... |
| 3846 | ... b: int |
| 3847 | >>> is_protocol(P) |
| 3848 | True |
| 3849 | >>> is_protocol(int) |
| 3850 | False |
| 3851 | """ |
| 3852 | return ( |
| 3853 | isinstance(tp, type) |
| 3854 | and getattr(tp, '_is_protocol', False) |
| 3855 | and tp != Protocol |
| 3856 | ) |
| 3857 | |
| 3858 | |
| 3859 | def get_protocol_members(tp: type, /) -> frozenset[str]: |
no outgoing calls
searching dependent graphs…