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
5 changes: 2 additions & 3 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ without the dedicated syntax, as documented below.

.. doctest::

>>> from typing import ParamSpec
>>> from typing import ParamSpec, get_origin
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't mind the change you're making here. But the reason why this doesn't currently fail when Sphinx runs our doctests in CI is because of this, which is run before every doctest block:

.. testsetup:: *
import typing
from dataclasses import dataclass
from typing import *

>>> P = ParamSpec("P")
>>> get_origin(P.args) is P
True
Expand Down Expand Up @@ -3065,8 +3065,7 @@ Introspection helpers
>>> class P(Protocol):
... def a(self) -> str: ...
... b: int
>>> get_protocol_members(P)
frozenset({'a', 'b'})
>>> assert get_protocol_members(P) == frozenset({'a', 'b'})
Comment thread
AlexWaygood marked this conversation as resolved.
Outdated
Comment thread
AlexWaygood marked this conversation as resolved.
Outdated

Raise :exc:`TypeError` for arguments that are not Protocols.

Expand Down
17 changes: 14 additions & 3 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
import pickle
import re
import sys
import warnings
from unittest import TestCase, main, skipUnless, skip
import os
import doctest
from unittest import TestCase, main, skip
from unittest.mock import patch
from copy import copy, deepcopy

Expand Down Expand Up @@ -45,7 +46,7 @@
import weakref
import types

from test.support import import_helper, captured_stderr, cpython_only
from test.support import captured_stderr, cpython_only, REPO_ROOT
from test import mod_generics_cache
from test import _typed_dict_helper

Expand Down Expand Up @@ -9465,5 +9466,15 @@ def test_is_not_instance_of_iterable(self):
self.assertNotIsInstance(type_to_test, collections.abc.Iterable)


def load_tests(loader, tests, pattern):
tests.addTests(doctest.DocFileSuite(
os.path.join(REPO_ROOT, 'Doc/library/typing.rst'),
module_relative=False,
# Some tests in `typing.rst` pretend to be executed in `__main__`:
globs={'__name__': '__main__'},
))
return tests


if __name__ == '__main__':
main()