From f5c3666e7a5dbbff7bd518d8f04df1a6037e1c1b Mon Sep 17 00:00:00 2001 From: Brian Schubert Date: Sun, 15 Mar 2026 16:02:00 -0400 Subject: [PATCH] Add `@type_check_only` to stub-only private classes in stdlib, round 2 --- stdlib/importlib/metadata/__init__.pyi | 3 ++- stdlib/statistics.pyi | 4 +++- stdlib/tkinter/ttk.pyi | 5 +++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/stdlib/importlib/metadata/__init__.pyi b/stdlib/importlib/metadata/__init__.pyi index 9286e92331c8..bb1b22f11a62 100644 --- a/stdlib/importlib/metadata/__init__.pyi +++ b/stdlib/importlib/metadata/__init__.pyi @@ -10,7 +10,7 @@ from importlib.abc import MetaPathFinder from os import PathLike from pathlib import Path from re import Pattern -from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload +from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias, deprecated, disjoint_base _T = TypeVar("_T") @@ -54,6 +54,7 @@ elif sys.version_info >= (3, 11): _EntryPointBase = DeprecatedTuple else: + @type_check_only class _EntryPointBase(NamedTuple): name: str value: str diff --git a/stdlib/statistics.pyi b/stdlib/statistics.pyi index 188bed3375bf..d9f282b99b66 100644 --- a/stdlib/statistics.pyi +++ b/stdlib/statistics.pyi @@ -3,7 +3,7 @@ from _typeshed import SupportsRichComparisonT from collections.abc import Callable, Hashable, Iterable, Sequence, Sized from decimal import Decimal from fractions import Fraction -from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar +from typing import Literal, NamedTuple, Protocol, SupportsFloat, SupportsIndex, TypeVar, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -44,7 +44,9 @@ _Seed: TypeAlias = int | float | str | bytes | bytearray # noqa: Y041 # Used in linear_regression _T_co = TypeVar("_T_co", covariant=True) +@type_check_only class _SizedIterable(Iterable[_T_co], Sized, Protocol[_T_co]): ... + class StatisticsError(ValueError): ... if sys.version_info >= (3, 11): diff --git a/stdlib/tkinter/ttk.pyi b/stdlib/tkinter/ttk.pyi index 7143c7cce592..0a6837201035 100644 --- a/stdlib/tkinter/ttk.pyi +++ b/stdlib/tkinter/ttk.pyi @@ -57,6 +57,7 @@ _VsapiStatespec: TypeAlias = tuple[Unpack[tuple[str, ...]], int] _P = ParamSpec("_P") _T = TypeVar("_T") +@type_check_only class _Layout(TypedDict, total=False): side: Literal["left", "right", "top", "bottom"] sticky: str # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty @@ -68,6 +69,7 @@ class _Layout(TypedDict, total=False): _LayoutSpec: TypeAlias = list[tuple[str, _Layout | None]] # Keep these in sync with the appropriate methods in Style +@type_check_only class _ElementCreateImageKwargs(TypedDict, total=False): border: _Padding height: float | str @@ -82,12 +84,15 @@ _ElementCreateArgsCrossPlatform: TypeAlias = ( | tuple[Literal["from"], str] # (fromelement is optional) ) if sys.platform == "win32" and sys.version_info >= (3, 13): + @type_check_only class _ElementCreateVsapiKwargsPadding(TypedDict, total=False): padding: _Padding + @type_check_only class _ElementCreateVsapiKwargsMargin(TypedDict, total=False): padding: _Padding + @type_check_only class _ElementCreateVsapiKwargsSize(TypedDict): width: float | str height: float | str