Skip to content

Commit a358dc2

Browse files
authored
[array] Add w typecode and deprecate u typecode (#14475)
1 parent d24394f commit a358dc2

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

stdlib/array.pyi

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite
33
from collections.abc import Iterable, MutableSequence
44
from types import GenericAlias
55
from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload
6-
from typing_extensions import Self, TypeAlias
6+
from typing_extensions import Self, TypeAlias, deprecated
77

88
_IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"]
99
_FloatTypeCode: TypeAlias = Literal["f", "d"]
10-
_UnicodeTypeCode: TypeAlias = Literal["u"]
10+
if sys.version_info >= (3, 13):
11+
_UnicodeTypeCode: TypeAlias = Literal["u", "w"]
12+
else:
13+
_UnicodeTypeCode: TypeAlias = Literal["u"]
1114
_TypeCode: TypeAlias = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode
1215

1316
_T = TypeVar("_T", int, float, str)
@@ -27,10 +30,23 @@ class array(MutableSequence[_T]):
2730
def __new__(
2831
cls: type[array[float]], typecode: _FloatTypeCode, initializer: bytes | bytearray | Iterable[float] = ..., /
2932
) -> array[float]: ...
30-
@overload
31-
def __new__(
32-
cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., /
33-
) -> array[str]: ...
33+
if sys.version_info >= (3, 13):
34+
@overload
35+
def __new__(
36+
cls: type[array[str]], typecode: Literal["w"], initializer: bytes | bytearray | Iterable[str] = ..., /
37+
) -> array[str]: ...
38+
@overload
39+
@deprecated("Deprecated since Python 3.3; will be removed in Python 3.16. Use 'w' typecode instead.")
40+
def __new__(
41+
cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., /
42+
) -> array[str]: ...
43+
else:
44+
@overload
45+
@deprecated("Deprecated since Python 3.3; will be removed in Python 3.16.")
46+
def __new__(
47+
cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., /
48+
) -> array[str]: ...
49+
3450
@overload
3551
def __new__(cls, typecode: str, initializer: Iterable[_T], /) -> Self: ...
3652
@overload

0 commit comments

Comments
 (0)