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"
```
This commit is contained in:
Kyle Altendorf
2021-10-25 19:28:33 -04:00
committed by GitHub
parent fd35084768
commit 9052674aa8

View File

@@ -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: ...