Skip to content

Commit 03b8c60

Browse files
authored
Support dict(foo.split() for foo in bar) with bytes (#10072)
1 parent d74bea5 commit 03b8c60

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

stdlib/builtins.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,10 +1032,12 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
10321032
def __init__(self, __iterable: Iterable[tuple[_KT, _VT]]) -> None: ...
10331033
@overload
10341034
def __init__(self: dict[str, _VT], __iterable: Iterable[tuple[str, _VT]], **kwargs: _VT) -> None: ...
1035-
# Next overload is for dict(string.split(sep) for string in iterable)
1035+
# Next two overloads are for dict(string.split(sep) for string in iterable)
10361036
# Cannot be Iterable[Sequence[_T]] or otherwise dict(["foo", "bar", "baz"]) is not an error
10371037
@overload
10381038
def __init__(self: dict[str, str], __iterable: Iterable[list[str]]) -> None: ...
1039+
@overload
1040+
def __init__(self: dict[bytes, bytes], __iterable: Iterable[list[bytes]]) -> None: ...
10391041
def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
10401042
def copy(self) -> dict[_KT, _VT]: ...
10411043
def keys(self) -> dict_keys[_KT, _VT]: ...

stdlib/collections/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
6262
def __init__(self: UserDict[str, _VT], __iterable: Iterable[tuple[str, _VT]], **kwargs: _VT) -> None: ...
6363
@overload
6464
def __init__(self: UserDict[str, str], __iterable: Iterable[list[str]]) -> None: ...
65+
@overload
66+
def __init__(self: UserDict[bytes, bytes], __iterable: Iterable[list[bytes]]) -> None: ...
6567
def __len__(self) -> int: ...
6668
def __getitem__(self, key: _KT) -> _VT: ...
6769
def __setitem__(self, key: _KT, item: _VT) -> None: ...

stdlib/multiprocessing/managers.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ class SyncManager(BaseManager):
197197
@overload
198198
def dict(self, __iterable: Iterable[list[str]]) -> DictProxy[str, str]: ...
199199
@overload
200+
def dict(self, __iterable: Iterable[list[bytes]]) -> DictProxy[bytes, bytes]: ...
201+
@overload
200202
def list(self, __sequence: Sequence[_T]) -> ListProxy[_T]: ...
201203
@overload
202204
def list(self) -> ListProxy[Any]: ...

test_cases/stdlib/builtins/check_dict.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,9 @@ def test_iterable_tuple_overload(x: Iterable[tuple[int, str]]) -> dict[int, str]
5050
assert_type(dict(i2, arg=1), Dict[str, int])
5151

5252
i3: Iterable[str] = ["a.b"]
53+
i4: Iterable[bytes] = [b"a.b"]
5354
assert_type(dict(string.split(".") for string in i3), Dict[str, str])
55+
assert_type(dict(string.split(b".") for string in i4), Dict[bytes, bytes])
56+
5457
dict(["foo", "bar", "baz"]) # type: ignore
58+
dict([b"foo", b"bar", b"baz"]) # type: ignore

0 commit comments

Comments
 (0)