From b3f685d557bfeaa2f20ff046ecc35bfb87a2bbef Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sun, 27 Jul 2025 15:41:39 +0400 Subject: [PATCH 1/3] [array] Add `w` typecode and deprecate `u` typecode --- stdlib/array.pyi | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/stdlib/array.pyi b/stdlib/array.pyi index bd96c9bc2d31..bd2ac38c088c 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -3,11 +3,14 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable, MutableSequence from types import GenericAlias from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] -_UnicodeTypeCode: TypeAlias = Literal["u"] +if sys.version_info >= (3, 13): + _UnicodeTypeCode: TypeAlias = Literal["u", "w"] +else: + _UnicodeTypeCode: TypeAlias = Literal["u"] _TypeCode: TypeAlias = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode _T = TypeVar("_T", int, float, str) @@ -27,10 +30,23 @@ class array(MutableSequence[_T]): def __new__( cls: type[array[float]], typecode: _FloatTypeCode, initializer: bytes | bytearray | Iterable[float] = ..., / ) -> array[float]: ... - @overload - def __new__( - cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., / - ) -> array[str]: ... + if sys.version_info >= (3, 13): + @overload + def __new__( + cls: type[array[str]], typecode: Literal["w"], initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + @overload + @deprecated("Deprecated since Python 3.3; will be removed in version 3.16. Use 'w' typecode instead.") + def __new__( + cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + else: + @overload + @deprecated("Deprecated since Python 3.3; will be removed in version 3.16.") + def __new__( + cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + @overload def __new__(cls, typecode: str, initializer: Iterable[_T], /) -> Self: ... @overload From 24e9c0fca35f42814ee47a2c99719a1d6ed101d1 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Fri, 8 Aug 2025 10:00:57 +0400 Subject: [PATCH 2/3] say Python instead of version --- stdlib/array.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/array.pyi b/stdlib/array.pyi index bd2ac38c088c..8f0b28e81835 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -36,13 +36,13 @@ class array(MutableSequence[_T]): cls: type[array[str]], typecode: Literal["w"], initializer: bytes | bytearray | Iterable[str] = ..., / ) -> array[str]: ... @overload - @deprecated("Deprecated since Python 3.3; will be removed in version 3.16. Use 'w' typecode instead.") + @deprecated("Deprecated since Python 3.3; will be removed in Python 3.16. Use 'w' typecode instead.") def __new__( cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., / ) -> array[str]: ... else: @overload - @deprecated("Deprecated since Python 3.3; will be removed in version 3.16.") + @deprecated("Deprecated since Python 3.3; will be removed in Python 3.16.") def __new__( cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., / ) -> array[str]: ... From ce9da1360d97f8426f2ed7f126ef1e1710147f6e Mon Sep 17 00:00:00 2001 From: Semyon Moroz Date: Fri, 8 Aug 2025 09:09:34 +0000 Subject: [PATCH 3/3] Update array.pyi Co-authored-by: Sebastian Rittau --- stdlib/array.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/array.pyi b/stdlib/array.pyi index 8f0b28e81835..94d44c527338 100644 --- a/stdlib/array.pyi +++ b/stdlib/array.pyi @@ -44,7 +44,7 @@ class array(MutableSequence[_T]): @overload @deprecated("Deprecated since Python 3.3; will be removed in Python 3.16.") def __new__( - cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., / + cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., / ) -> array[str]: ... @overload