Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address review + add a couple of comments
  • Loading branch information
AlexWaygood committed Jan 5, 2024
commit e0e108b43f50e9428888a08f3fdb922110860288
6 changes: 0 additions & 6 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3472,12 +3472,6 @@ def meth(self): pass
vars(NonPR).keys(), vars(D).keys() | acceptable_extra_attrs
)

def test_nonruntime_protocols_not_unnecessarily_introspected(self) -> None:
class Foo(Protocol):
x = 1

self.assertFalse(hasattr(Foo, "__non_callable_proto_members__"))

def test_custom_subclasshook(self):
class P(Protocol):
x = 1
Expand Down
2 changes: 2 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,7 @@ def __subclasscheck__(cls, other):
"@runtime_checkable protocols"
)
if (
# this attribute is set by @runtime_checkable:
cls.__non_callable_proto_members__
and cls.__dict__.get("__subclasshook__") is _proto_hook
):
Expand Down Expand Up @@ -1884,6 +1885,7 @@ def __instancecheck__(cls, instance):
val = getattr_static(instance, attr)
except AttributeError:
break
# this attribute is set by @runtime_checkable:
if val is None and attr not in cls.__non_callable_proto_members__:
break
else:
Expand Down