mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 20:54:28 +08:00
builtins, collections: Fix unconstrained overloads for container constructors (#7944)
See https://github.com/microsoft/pyright/issues/3501#issuecomment-1135979479 Related to #7928
This commit is contained in:
@@ -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
|
||||
@overload
|
||||
def __init__(self: dict[_KT, _VT]) -> None: ...
|
||||
def __init__(self) -> None: ...
|
||||
@overload
|
||||
def __init__(self: dict[str, _VT], **kwargs: _VT) -> None: ...
|
||||
@overload
|
||||
@@ -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]: ...
|
||||
@@ -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]: ...
|
||||
|
||||
@@ -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
|
||||
@@ -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: ...
|
||||
@@ -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: ...
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user