add several NamedTuple base classes (#12987)

This commit is contained in:
Stephen Morton
2024-11-21 01:52:31 -08:00
committed by GitHub
parent 0fb3a092c7
commit 32f48a5eae
11 changed files with 47 additions and 52 deletions

View File

@@ -3,7 +3,7 @@ import types
import unittest
from _typeshed import ExcInfo
from collections.abc import Callable
from typing import Any, ClassVar, NamedTuple
from typing import Any, NamedTuple, type_check_only
from typing_extensions import Self, TypeAlias
__all__ = [
@@ -42,17 +42,15 @@ __all__ = [
"debug",
]
# 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
@type_check_only
class _TestResultsBase(NamedTuple):
failed: int
attempted: int
_fields: ClassVar = ("failed", "attempted") # type: ignore[misc]
__match_args__ = ("failed", "attempted") # type: ignore[misc]
__doc__: None # type: ignore[misc]
class TestResults(_TestResultsBase):
def __new__(cls, failed: int, attempted: int, *, skipped: int = 0) -> Self: ...
skipped: int
else:
class TestResults(NamedTuple):