From 089953ed841a201137f81dbd276767d2af6b3072 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sun, 8 Sep 2024 05:38:13 -0500 Subject: [PATCH] Fix doctest for 3.13 (#12625) --- stdlib/@tests/stubtest_allowlists/py313.txt | 4 ++-- stdlib/doctest.pyi | 26 +++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/stdlib/@tests/stubtest_allowlists/py313.txt b/stdlib/@tests/stubtest_allowlists/py313.txt index 7a96b4b2b..a36060cd8 100644 --- a/stdlib/@tests/stubtest_allowlists/py313.txt +++ b/stdlib/@tests/stubtest_allowlists/py313.txt @@ -4,8 +4,6 @@ # TODO: triage these new errors _tkinter.create -doctest.TestResults.__doc__ -doctest.TestResults.__new__ importlib.resources.Anchor importlib.resources.Resource importlib.resources.__all__ @@ -119,6 +117,8 @@ ast.ImportFrom.level # None on the class, but never None on instances builtins.property.__set_name__ # Doesn't actually exist collections\.UserList\.index # ignoring pos-or-keyword parameter dataclasses.KW_ONLY # white lies around defaults +doctest.TestResults.__match_args__ # Stubtest doesn't pick up override +doctest.TestResults._fields # Stubtest doesn't pick up override enum.auto.__init__ # The stub for enum.auto is nothing like the implementation enum.auto.value # The stub for enum.auto is nothing like the implementation functools._lru_cache_wrapper.cache_parameters # Cannot be detected statically diff --git a/stdlib/doctest.pyi b/stdlib/doctest.pyi index 7e334ef0c..438008302 100644 --- a/stdlib/doctest.pyi +++ b/stdlib/doctest.pyi @@ -1,9 +1,10 @@ +import sys import types import unittest from _typeshed import ExcInfo from collections.abc import Callable -from typing import Any, NamedTuple -from typing_extensions import TypeAlias +from typing import Any, ClassVar, NamedTuple +from typing_extensions import Self, TypeAlias __all__ = [ "register_optionflag", @@ -41,9 +42,22 @@ __all__ = [ "debug", ] -class TestResults(NamedTuple): - failed: int - attempted: int +# MyPy errors on conditionals within named tuples. + +if sys.version_info >= (3, 13): + class TestResults(NamedTuple): + def __new__(cls, failed: int, attempted: int, *, skipped: int = 0) -> Self: ... # type: ignore[misc] + skipped: int + failed: int + attempted: int + _fields: ClassVar = ("failed", "attempted") # type: ignore[misc] + __match_args__ = ("failed", "attempted") # type: ignore[misc] + __doc__: None # type: ignore[misc] + +else: + class TestResults(NamedTuple): + failed: int + attempted: int OPTIONFLAGS_BY_NAME: dict[str, int] @@ -134,6 +148,8 @@ class DocTestRunner: original_optionflags: int tries: int failures: int + if sys.version_info >= (3, 13): + skips: int test: DocTest def __init__(self, checker: OutputChecker | None = None, verbose: bool | None = None, optionflags: int = 0) -> None: ... def report_start(self, out: _Out, test: DocTest, example: Example) -> None: ...