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

Method __subclasscheck__

Lib/typing.py:2040–2074  ·  view source on GitHub ↗
(cls, other)

Source from the content-addressed store, hash-verified

2038 cls.__protocol_attrs__ = _get_protocol_attrs(cls)
2039
2040 def __subclasscheck__(cls, other):
2041 if cls is Protocol:
2042 return type.__subclasscheck__(cls, other)
2043 if (
2044 getattr(cls, '_is_protocol', False)
2045 and not _allow_reckless_class_checks()
2046 ):
2047 if not getattr(cls, '_is_runtime_protocol', False):
2048 _type_check_issubclass_arg_1(other)
2049 raise TypeError(
2050 "Instance and class checks can only be used with "
2051 "@runtime_checkable protocols"
2052 )
2053 if getattr(cls, '__typing_is_deprecated_inherited_runtime_protocol__', False):
2054 # See GH-132604.
2055 import warnings
2056 depr_message = (
2057 f"{cls!r} isn't explicitly decorated with @runtime_checkable but "
2058 "it is used in issubclass() or isinstance(). Instance and class "
2059 "checks can only be used with @runtime_checkable protocols. "
2060 "This will raise a TypeError in Python 3.20."
2061 )
2062 warnings.warn(depr_message, category=DeprecationWarning, stacklevel=2)
2063 if (
2064 # this attribute is set by @runtime_checkable:
2065 cls.__non_callable_proto_members__
2066 and cls.__dict__.get("__subclasshook__") is _proto_hook
2067 ):
2068 _type_check_issubclass_arg_1(other)
2069 non_method_attrs = sorted(cls.__non_callable_proto_members__)
2070 raise TypeError(
2071 "Protocols with non-method members don't support issubclass()."
2072 f" Non-method members: {str(non_method_attrs)[1:-1]}."
2073 )
2074 return _abc_subclasscheck(cls, other)
2075
2076 def __instancecheck__(cls, instance):
2077 # We need this method for situations where attributes are

Callers

nothing calls this directly

Calls 6

strFunction · 0.85
__subclasscheck__Method · 0.45
warnMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected