Skip to content

typing.py contains two doctests that are not executed, ever #112155

Closed

Description

@sobolevn

Feature or enhancement

typing.py contains at least two doctests:

cpython/Lib/typing.py

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

Activity

  1. self-assigned this
    on Nov 16, 2023
  2. added a commit that references this issue on Nov 16, 2023
  3. added a commit that references this issue on Nov 16, 2023
  4. AlexWaygood commented on Nov 16, 2023

    @AlexWaygood
    Member

    The change has been applied to main. Lib/typing.py has no doctests on the 3.12 or 3.11 branches, so there's no need to backport this.

    Thanks @sobolevn!

  5. added 2 commits that reference this issue on Nov 18, 2023
  6. added 2 commits that reference this issue on Nov 18, 2023
  7. added a commit that references this issue on Feb 11, 2024
  8. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions