From 9052674aa8f059ac68f8726005751ebb53a271ce Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Mon, 25 Oct 2021 19:28:33 -0400 Subject: [PATCH] bytes.fromhex() returns cls instance, not bytes (#6201) ```console $ cat y.py import typing class MyBytes(bytes): pass x = MyBytes.fromhex("abcd") if typing.TYPE_CHECKING: reveal_type(x) else: print(x.__class__.__name__) ``` ```console $ for v in 3.6 3.7 3.8 3.9 3.10; do echo -n "$v: " ; python$v y.py; done 3.6: MyBytes 3.7: MyBytes 3.8: MyBytes 3.9: MyBytes 3.10: MyBytes ``` ```console $ venv/bin/mypy y.py y.py:9: note: Revealed type is "builtins.bytes" ``` --- stdlib/builtins.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 225388cc9..4694042ca 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -493,7 +493,7 @@ class bytes(ByteString): def upper(self) -> bytes: ... def zfill(self, __width: SupportsIndex) -> bytes: ... @classmethod - def fromhex(cls, __s: str) -> bytes: ... + def fromhex(cls: Type[_T], __s: str) -> _T: ... @staticmethod def maketrans(__frm: bytes, __to: bytes) -> bytes: ... def __len__(self) -> int: ...