MCPcopy Index your code
hub / github.com/RustPython/RustPython / __instancecheck__

Method __instancecheck__

Lib/typing.py:2027–2058  ·  view source on GitHub ↗
(cls, instance)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

getattr_staticFunction · 0.90
getattrFunction · 0.85
_abc_instancecheckFunction · 0.85
__instancecheck__Method · 0.45

Tested by

no test coverage detected