From 9824df0b0bfbe2e503e55e4c6697be6978f2dac5 Mon Sep 17 00:00:00 2001 From: ZeroIntensity Date: Sat, 17 Aug 2024 09:40:46 -0400 Subject: [PATCH 1/5] Add operator.is_none and operator.is_not_none --- stdlib/_operator.pyi | 6 +++++- stdlib/operator.pyi | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index 69ee563b5cf4..b0cb02ad44ae 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsGetItem from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from typing import Any, AnyStr, Generic, Protocol, SupportsAbs, SupportsIndex, TypeVar, final, overload -from typing_extensions import ParamSpec, TypeAlias, TypeVarTuple, Unpack +from typing_extensions import ParamSpec, TypeAlias, TypeVarTuple, Unpack, TypeGuard, TypeIs _R = TypeVar("_R") _T = TypeVar("_T") @@ -145,3 +145,7 @@ if sys.version_info >= (3, 11): def call(obj: Callable[_P, _R], /, *args: _P.args, **kwargs: _P.kwargs) -> _R: ... def _compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ... + +if sys.version_info >= (3, 14): + def is_none(a: Any, /) -> TypeGuard[None]: ... + def is_not_none(a: _T | None, /) -> TypeIs[_T]: ... diff --git a/stdlib/operator.pyi b/stdlib/operator.pyi index a0e5df7977da..1a817f00f3c1 100644 --- a/stdlib/operator.pyi +++ b/stdlib/operator.pyi @@ -61,6 +61,9 @@ __all__ = [ if sys.version_info >= (3, 11): __all__ += ["call"] +if sys.version_info >= (3, 14): + __all__ += ["is_none", "is_not_none"] + __lt__ = lt __le__ = le __eq__ = eq From fddc9bdace7f869a220e0abe9ae5d88a9d67b38c Mon Sep 17 00:00:00 2001 From: ZeroIntensity Date: Sat, 17 Aug 2024 09:43:48 -0400 Subject: [PATCH 2/5] Use a more narrow type guard. --- stdlib/_operator.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index b0cb02ad44ae..06a640102bbb 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsGetItem from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from typing import Any, AnyStr, Generic, Protocol, SupportsAbs, SupportsIndex, TypeVar, final, overload -from typing_extensions import ParamSpec, TypeAlias, TypeVarTuple, Unpack, TypeGuard, TypeIs +from typing_extensions import ParamSpec, TypeAlias, TypeVarTuple, Unpack, TypeIs _R = TypeVar("_R") _T = TypeVar("_T") @@ -147,5 +147,5 @@ if sys.version_info >= (3, 11): def _compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ... if sys.version_info >= (3, 14): - def is_none(a: Any, /) -> TypeGuard[None]: ... + def is_none(a: _T | None, /) -> TypeIs[None]: ... def is_not_none(a: _T | None, /) -> TypeIs[_T]: ... From a166f2d184db66113091ce3e724f7f320e56848f Mon Sep 17 00:00:00 2001 From: ZeroIntensity Date: Sat, 17 Aug 2024 09:45:50 -0400 Subject: [PATCH 3/5] Remove useless generic. --- stdlib/_operator.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index 06a640102bbb..ae973973c3fe 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -147,5 +147,5 @@ if sys.version_info >= (3, 11): def _compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ... if sys.version_info >= (3, 14): - def is_none(a: _T | None, /) -> TypeIs[None]: ... + def is_none(a: Any | None, /) -> TypeIs[None]: ... def is_not_none(a: _T | None, /) -> TypeIs[_T]: ... From e443ca75d82934b5eba79434497ad8ffda2889e4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 17 Aug 2024 13:48:09 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_operator.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index ae973973c3fe..a7629ae99b8f 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import SupportsGetItem from collections.abc import Callable, Container, Iterable, MutableMapping, MutableSequence, Sequence from typing import Any, AnyStr, Generic, Protocol, SupportsAbs, SupportsIndex, TypeVar, final, overload -from typing_extensions import ParamSpec, TypeAlias, TypeVarTuple, Unpack, TypeIs +from typing_extensions import ParamSpec, TypeAlias, TypeIs, TypeVarTuple, Unpack _R = TypeVar("_R") _T = TypeVar("_T") From 3adacf58ae12985837b7d062b9d6da83d5f9e025 Mon Sep 17 00:00:00 2001 From: Peter Bierma Date: Sat, 17 Aug 2024 11:09:38 -0400 Subject: [PATCH 5/5] Update stdlib/_operator.pyi Co-authored-by: Akuli --- stdlib/_operator.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_operator.pyi b/stdlib/_operator.pyi index a7629ae99b8f..1b0083f4e274 100644 --- a/stdlib/_operator.pyi +++ b/stdlib/_operator.pyi @@ -147,5 +147,5 @@ if sys.version_info >= (3, 11): def _compare_digest(a: AnyStr, b: AnyStr, /) -> bool: ... if sys.version_info >= (3, 14): - def is_none(a: Any | None, /) -> TypeIs[None]: ... + def is_none(a: object, /) -> TypeIs[None]: ... def is_not_none(a: _T | None, /) -> TypeIs[_T]: ...