Feature or enhancement
typing.py contains at least two doctests:
|
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
Feature or enhancement
typing.pycontains at least two doctests:cpython/Lib/typing.py
Lines 3377 to 3414 in 81ab0e8
But, they are not ever executed.
I propose to add a
DocTestSuitetotest_typingto run these tests.Note, that this is related but not similar to #111682
Linked PRs
typing.pydoctests during tests #112156typing.pydoctests during tests (GH-112156) #112230typing.pydoctests during tests (GH-112156) #112231