Skip to content
Prev Previous commit
Next Next commit
Merge branch 'main' into protocol-attrs-cache-1
  • Loading branch information
AlexWaygood authored Apr 2, 2023
commit e8a63045eb5d108483e71ba8714797e8f7e835cd
14 changes: 9 additions & 5 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2036,11 +2036,15 @@ def __instancecheck__(cls, instance):
return True

if is_protocol_cls:
if all(hasattr(instance, attr) and
# All *methods* can be blocked by setting them to None.
(not callable(getattr(cls, attr, None)) or
getattr(instance, attr) is not None)
for attr in cls.__protocol_attrs__):
getattr_static = _lazy_load_getattr_static()
for attr in cls.__protocol_attrs__:
try:
val = getattr_static(instance, attr)
except AttributeError:
break
if callable(getattr(cls, attr, None)) and val is None:
break
else:
return True

return super().__instancecheck__(instance)
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.