(cls, instance)
| 2025 | return _abc_subclasscheck(cls, other) |
| 2026 | |
| 2027 | def __instancecheck__(cls, instance): |
| 2028 | # We need this method for situations where attributes are |
| 2029 | # assigned in __init__. |
| 2030 | if cls is Protocol: |
| 2031 | return type.__instancecheck__(cls, instance) |
| 2032 | if not getattr(cls, "_is_protocol", False): |
| 2033 | # i.e., it's a concrete subclass of a protocol |
| 2034 | return _abc_instancecheck(cls, instance) |
| 2035 | |
| 2036 | if ( |
| 2037 | not getattr(cls, '_is_runtime_protocol', False) and |
| 2038 | not _allow_reckless_class_checks() |
| 2039 | ): |
| 2040 | raise TypeError("Instance and class checks can only be used with" |
| 2041 | " @runtime_checkable protocols") |
| 2042 | |
| 2043 | if _abc_instancecheck(cls, instance): |
| 2044 | return True |
| 2045 | |
| 2046 | getattr_static = _lazy_load_getattr_static() |
| 2047 | for attr in cls.__protocol_attrs__: |
| 2048 | try: |
| 2049 | val = getattr_static(instance, attr) |
| 2050 | except AttributeError: |
| 2051 | break |
| 2052 | # this attribute is set by @runtime_checkable: |
| 2053 | if val is None and attr not in cls.__non_callable_proto_members__: |
| 2054 | break |
| 2055 | else: |
| 2056 | return True |
| 2057 | |
| 2058 | return False |
| 2059 | |
| 2060 | |
| 2061 | @classmethod |
nothing calls this directly
no test coverage detected