From 361b8ca0805c3027da61c89d06327f730606a2e0 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sun, 9 Nov 2025 17:36:01 +0400 Subject: [PATCH 1/4] [unittest] Annotate three_way_cmp Source: https://github.com/python/cpython/blob/3ce2d57b2f02030353af314d89c5f6215d2f5c96/Lib/unittest/util.py#L115 --- stdlib/unittest/util.pyi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stdlib/unittest/util.pyi b/stdlib/unittest/util.pyi index 31c830e8268a..c2b227458cb9 100644 --- a/stdlib/unittest/util.pyi +++ b/stdlib/unittest/util.pyi @@ -1,8 +1,10 @@ +from _operator import _SupportsComparison from collections.abc import MutableSequence, Sequence -from typing import Any, Final, TypeVar +from typing import Final, Literal, TypeVar from typing_extensions import TypeAlias _T = TypeVar("_T") +_Comp = TypeVar("_Comp", bound=_SupportsComparison) _Mismatch: TypeAlias = tuple[_T, _T, int] _MAX_LENGTH: Final = 80 @@ -18,6 +20,6 @@ def safe_repr(obj: object, short: bool = False) -> str: ... def strclass(cls: type) -> str: ... def sorted_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> tuple[list[_T], list[_T]]: ... def unorderable_list_difference(expected: MutableSequence[_T], actual: MutableSequence[_T]) -> tuple[list[_T], list[_T]]: ... -def three_way_cmp(x: Any, y: Any) -> int: ... +def three_way_cmp(x: _Comp, y: _Comp) -> Literal[-1, 0, 1]: ... def _count_diff_all_purpose(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ... def _count_diff_hashable(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ... From 6caad73dffdcc2f476186c582b5f35eb20fd403e Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sun, 9 Nov 2025 17:40:19 +0400 Subject: [PATCH 2/4] do not use typevar --- stdlib/unittest/util.pyi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stdlib/unittest/util.pyi b/stdlib/unittest/util.pyi index c2b227458cb9..f0465ef1ca6b 100644 --- a/stdlib/unittest/util.pyi +++ b/stdlib/unittest/util.pyi @@ -4,7 +4,6 @@ from typing import Final, Literal, TypeVar from typing_extensions import TypeAlias _T = TypeVar("_T") -_Comp = TypeVar("_Comp", bound=_SupportsComparison) _Mismatch: TypeAlias = tuple[_T, _T, int] _MAX_LENGTH: Final = 80 @@ -20,6 +19,6 @@ def safe_repr(obj: object, short: bool = False) -> str: ... def strclass(cls: type) -> str: ... def sorted_list_difference(expected: Sequence[_T], actual: Sequence[_T]) -> tuple[list[_T], list[_T]]: ... def unorderable_list_difference(expected: MutableSequence[_T], actual: MutableSequence[_T]) -> tuple[list[_T], list[_T]]: ... -def three_way_cmp(x: _Comp, y: _Comp) -> Literal[-1, 0, 1]: ... +def three_way_cmp(x: _SupportsComparison, y: _SupportsComparison) -> Literal[-1, 0, 1]: ... def _count_diff_all_purpose(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ... def _count_diff_hashable(actual: Sequence[_T], expected: Sequence[_T]) -> list[_Mismatch[_T]]: ... From 6e4dc6f70eddd75a91a6700e335ccf95a8a10aff Mon Sep 17 00:00:00 2001 From: donBarbos Date: Mon, 10 Nov 2025 21:23:07 +0400 Subject: [PATCH 3/4] like this? :) --- stdlib/unittest/util.pyi | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/stdlib/unittest/util.pyi b/stdlib/unittest/util.pyi index f0465ef1ca6b..763c1478f5e6 100644 --- a/stdlib/unittest/util.pyi +++ b/stdlib/unittest/util.pyi @@ -1,10 +1,26 @@ -from _operator import _SupportsComparison from collections.abc import MutableSequence, Sequence -from typing import Final, Literal, TypeVar +from typing import Any, Final, Literal, Protocol, TypeVar, type_check_only from typing_extensions import TypeAlias +@type_check_only +class _SupportsDunderLT(Protocol): + def __lt__(self, other: Any, /) -> bool: ... + +@type_check_only +class _SupportsDunderGT(Protocol): + def __gt__(self, other: Any, /) -> bool: ... + +@type_check_only +class _SupportsDunderLE(Protocol): + def __le__(self, other: Any, /) -> bool: ... + +@type_check_only +class _SupportsDunderGE(Protocol): + def __ge__(self, other: Any, /) -> bool: ... + _T = TypeVar("_T") _Mismatch: TypeAlias = tuple[_T, _T, int] +_SupportsComparison: TypeAlias = _SupportsDunderLE | _SupportsDunderGE | _SupportsDunderGT | _SupportsDunderLT _MAX_LENGTH: Final = 80 _PLACEHOLDER_LEN: Final = 12 From b794f59ce34d409aea0c84484888f11fed0412dd Mon Sep 17 00:00:00 2001 From: donBarbos Date: Mon, 10 Nov 2025 21:29:45 +0400 Subject: [PATCH 4/4] emptry commit to trigger CI