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
18 changes: 18 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3134,6 +3134,24 @@ def bar(self, x: str) -> str:

self.assertIsInstance(Test(), PSub)

def test_pep695_generic_protocol_callable_members(self):
@runtime_checkable
class Foo[T_co](Protocol):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is a T_contra :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed my mind, now I hate Hungarian notation

def meth(self, x: T_co) -> None: ...

class Bar[T_co]:
def meth(self, x: T_co) -> None: ...

self.assertIsInstance(Bar(), Foo)
self.assertIsSubclass(Bar, Foo)

@runtime_checkable
class SupportsTrunc[T_co](Protocol):
def __trunc__(self) -> T_co: ...

self.assertIsInstance(0.0, SupportsTrunc)
self.assertIsSubclass(float, SupportsTrunc)

def test_init_called(self):
T = TypeVar('T')

Expand Down
2 changes: 1 addition & 1 deletion Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ class _TypingEllipsis:
_TYPING_INTERNALS = frozenset({
'__parameters__', '__orig_bases__', '__orig_class__',
'_is_protocol', '_is_runtime_protocol', '__protocol_attrs__',
'__callable_proto_members_only__',
'__callable_proto_members_only__', '__type_params__',
})

_SPECIAL_NAMES = frozenset({
Expand Down