Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions stdlib/builtins.pyi
Original file line numberDiff line numberDiff line change
Expand Up@@ -909,7 +909,7 @@ class list(MutableSequence[_T], Generic[_T]):
class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
# __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a similar change to collections.UserDict.__init__

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, made similar changes to constructors in that file.

@overload
def __init__(self: dict[_KT, _VT]) -> None: ...
def __init__(self) -> None: ...
@overload
def __init__(self: dict[str, _VT], **kwargs: _VT) -> None: ...
@overload
Expand DownExpand Up@@ -962,7 +962,10 @@ class dict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
def __ior__(self: Self, __value: Iterable[tuple[_KT, _VT]]) -> Self: ...

class set(MutableSet[_T], Generic[_T]):
def __init__(self, __iterable: Iterable[_T] = ...) -> None: ...
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, __iterable: Iterable[_T]) -> None: ...
def add(self, __element: _T) -> None: ...
def copy(self) -> set[_T]: ...
def difference(self, *s: Iterable[Any]) -> set[_T]: ...
Expand DownExpand Up@@ -998,7 +1001,10 @@ class set(MutableSet[_T], Generic[_T]):
def __class_getitem__(cls, __item: Any) -> GenericAlias: ...

class frozenset(AbstractSet[_T_co], Generic[_T_co]):
def __init__(self, __iterable: Iterable[_T_co] = ...) -> None: ...
@overload
def __init__(self) -> None: ...
@overload
def __init__(self, __iterable: Iterable[_T_co]) -> None: ...
def copy(self) -> frozenset[_T_co]: ...
def difference(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
def intersection(self, *s: Iterable[object]) -> frozenset[_T_co]: ...
Expand Down
16 changes: 11 additions & 5 deletions stdlib/collections/__init__.pyi
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,7 +43,7 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):
data: dict[_KT, _VT]
# __init__ should be kept roughly in line with `dict.__init__`, which has the same semantics
@overload
def __init__(self: UserDict[_KT, _VT], __dict: None = ...) -> None: ...
def __init__(self, __dict: None = ...) -> None: ...
@overload
def __init__(self: UserDict[str, _VT], __dict: None = ..., **kwargs: _VT) -> None: ...
@overload
Expand DownExpand Up@@ -82,7 +82,10 @@ class UserDict(MutableMapping[_KT, _VT], Generic[_KT, _VT]):

class UserList(MutableSequence[_T]):
data: list[_T]
def __init__(self, initlist: Iterable[_T] | None = ...) -> None: ...
@overload
def __init__(self, initlist: None = ...) -> None: ...
@overload
def __init__(self, initlist: Iterable[_T]) -> None: ...
def __lt__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __le__(self, other: list[_T] | UserList[_T]) -> bool: ...
def __gt__(self, other: list[_T] | UserList[_T]) -> bool: ...
Expand DownExpand Up@@ -214,7 +217,10 @@ class UserString(Sequence[UserString]):
class deque(MutableSequence[_T], Generic[_T]):
@property
def maxlen(self) -> int | None: ...
def __init__(self, iterable: Iterable[_T] = ..., maxlen: int | None = ...) -> None: ...
@overload
def __init__(self, *, maxlen: int | None = ...) -> None: ...
@overload
def __init__(self, iterable: Iterable[_T], maxlen: int | None = ...) -> None: ...
def append(self, __x: _T) -> None: ...
def appendleft(self, __x: _T) -> None: ...
def copy(self: Self) -> Self: ...
Expand DownExpand Up@@ -248,7 +254,7 @@ class deque(MutableSequence[_T], Generic[_T]):

class Counter(dict[_T, int], Generic[_T]):
@overload
def __init__(self: Counter[_T], __iterable: None = ...) -> None: ...
def __init__(self, __iterable: None = ...) -> None: ...
@overload
def __init__(self: Counter[str], __iterable: None = ..., **kwargs: int) -> None: ...
@overload
Expand DownExpand Up@@ -340,7 +346,7 @@ class OrderedDict(dict[_KT, _VT], Reversible[_KT], Generic[_KT, _VT]):
class defaultdict(dict[_KT, _VT], Generic[_KT, _VT]):
default_factory: Callable[[], _VT] | None
@overload
def __init__(self: defaultdict[_KT, _VT]) -> None: ...
def __init__(self) -> None: ...
@overload
def __init__(self: defaultdict[str, _VT], **kwargs: _VT) -> None: ...
@overload
Expand Down