From a06e16eae236cff4db71be0aeb7a2172ddd1aef9 Mon Sep 17 00:00:00 2001 From: Guo Ci Date: Thu, 4 Dec 2025 14:59:52 -0500 Subject: [PATCH] [stdlib] Update `fromhex` method `bytes` and `bytesarray` (#15103) docs: https://docs.python.org/dev/library/stdtypes.html#bytes.fromhex https://docs.python.org/dev/library/stdtypes.html#bytearray.fromhex --- stdlib/builtins.pyi | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 38be452e8..ed2217e79 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -731,8 +731,13 @@ class bytes(Sequence[int]): def translate(self, table: ReadableBuffer | None, /, delete: ReadableBuffer = b"") -> bytes: ... def upper(self) -> bytes: ... def zfill(self, width: SupportsIndex, /) -> bytes: ... - @classmethod - def fromhex(cls, string: str, /) -> Self: ... + if sys.version_info >= (3, 14): + @classmethod + def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ... + else: + @classmethod + def fromhex(cls, string: str, /) -> Self: ... + @staticmethod def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ... def __len__(self) -> int: ... @@ -836,8 +841,13 @@ class bytearray(MutableSequence[int]): def translate(self, table: ReadableBuffer | None, /, delete: bytes = b"") -> bytearray: ... def upper(self) -> bytearray: ... def zfill(self, width: SupportsIndex, /) -> bytearray: ... - @classmethod - def fromhex(cls, string: str, /) -> Self: ... + if sys.version_info >= (3, 14): + @classmethod + def fromhex(cls, string: str | ReadableBuffer, /) -> Self: ... + else: + @classmethod + def fromhex(cls, string: str, /) -> Self: ... + @staticmethod def maketrans(frm: ReadableBuffer, to: ReadableBuffer, /) -> bytes: ... def __len__(self) -> int: ...