mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
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:
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user