-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
typing.py
contains at least two doctests:
Lines 3377 to 3414 in 81ab0e8
def is_protocol(tp: type, /) -> bool: | |
"""Return True if the given type is a Protocol. | |
Example:: | |
>>> from typing import Protocol, is_protocol | |
>>> class P(Protocol): | |
... def a(self) -> str: ... | |
... b: int | |
>>> is_protocol(P) | |
True | |
>>> is_protocol(int) | |
False | |
""" | |
return ( | |
isinstance(tp, type) | |
and getattr(tp, '_is_protocol', False) | |
and tp != Protocol | |
) | |
def get_protocol_members(tp: type, /) -> frozenset[str]: | |
"""Return the set of members defined in a Protocol. | |
Example:: | |
>>> from typing import Protocol, get_protocol_members | |
>>> class P(Protocol): | |
... def a(self) -> str: ... | |
... b: int | |
>>> get_protocol_members(P) | |
frozenset({'a', 'b'}) | |
Raise a TypeError for arguments that are not Protocols. | |
""" | |
if not is_protocol(tp): | |
raise TypeError(f'{tp!r} is not a Protocol') | |
return frozenset(tp.__protocol_attrs__) |
But, they are not ever executed.
I propose to add a DocTestSuite
to test_typing
to run these tests.
Note, that this is related but not similar to #111682
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement