Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 47753ec

Browse filesBrowse files
authored
gh-74690: typing: Simplify and optimise _ProtocolMeta.__instancecheck__ (#103159)
1 parent 264c00a commit 47753ec
Copy full SHA for 47753ec

File tree

Expand file treeCollapse file tree

1 file changed

+3
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+3
-11
lines changed

‎Lib/typing.py

Copy file name to clipboardExpand all lines: Lib/typing.py
+3-11Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,20 +2024,12 @@ def __instancecheck__(cls, instance):
20242024
raise TypeError("Instance and class checks can only be used with"
20252025
" @runtime_checkable protocols")
20262026

2027-
if not is_protocol_cls and issubclass(instance.__class__, cls):
2028-
return True
2029-
2030-
protocol_attrs = _get_protocol_attrs(cls)
2031-
2032-
if (
2033-
_is_callable_members_only(cls, protocol_attrs)
2034-
and issubclass(instance.__class__, cls)
2035-
):
2027+
if super().__instancecheck__(instance):
20362028
return True
20372029

20382030
if is_protocol_cls:
20392031
getattr_static = _lazy_load_getattr_static()
2040-
for attr in protocol_attrs:
2032+
for attr in _get_protocol_attrs(cls):
20412033
try:
20422034
val = getattr_static(instance, attr)
20432035
except AttributeError:
@@ -2047,7 +2039,7 @@ def __instancecheck__(cls, instance):
20472039
else:
20482040
return True
20492041

2050-
return super().__instancecheck__(instance)
2042+
return False
20512043

20522044

20532045
class Protocol(Generic, metaclass=_ProtocolMeta):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.