MCPcopy Index your code
hub / github.com/python/cpython / is_protocol

Function is_protocol

Lib/typing.py:3838–3856  ·  view source on GitHub ↗

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, /)

Source from the content-addressed store, hash-verified

3836
3837
3838def 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
3859def get_protocol_members(tp: type, /) -> frozenset[str]:

Callers 2

test_is_protocolMethod · 0.90
get_protocol_membersFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_is_protocolMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…