mirror of
https://github.com/davidhalter/typeshed.git
synced 2026-02-06 18:07:39 +08:00
Stop inheriting Sized in collection ABCs (#2658)
Instead define abstract __len__ in affected classes. Fixes #2655 without breaking https://github.com/rominf/ordered-set-stubs/issues/1
This commit is contained in:
@@ -235,11 +235,18 @@ class Container(Protocol[_T_co]):
|
||||
|
||||
if sys.version_info >= (3, 6):
|
||||
@runtime
|
||||
class Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
|
||||
class Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
|
||||
# Implement Sized (but don't have it as a base class).
|
||||
@abstractmethod
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
_Collection = Collection
|
||||
else:
|
||||
@runtime
|
||||
class _Collection(Sized, Iterable[_T_co], Container[_T_co], Protocol[_T_co]): ...
|
||||
class _Collection(Iterable[_T_co], Container[_T_co], Protocol[_T_co]):
|
||||
# Implement Sized (but don't have it as a base class).
|
||||
@abstractmethod
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
class Sequence(_Collection[_T_co], Reversible[_T_co], Generic[_T_co]):
|
||||
@overload
|
||||
@@ -317,14 +324,14 @@ class MutableSet(AbstractSet[_T], Generic[_T]):
|
||||
def __ixor__(self, s: AbstractSet[_S]) -> MutableSet[Union[_T, _S]]: ...
|
||||
def __isub__(self, s: AbstractSet[Any]) -> MutableSet[_T]: ...
|
||||
|
||||
class MappingView(Sized):
|
||||
class MappingView:
|
||||
def __len__(self) -> int: ...
|
||||
|
||||
class ItemsView(AbstractSet[Tuple[_KT_co, _VT_co]], MappingView, Generic[_KT_co, _VT_co]):
|
||||
class ItemsView(MappingView, AbstractSet[Tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]):
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
|
||||
|
||||
class KeysView(AbstractSet[_KT_co], MappingView, Generic[_KT_co]):
|
||||
class KeysView(MappingView, AbstractSet[_KT_co], Generic[_KT_co]):
|
||||
def __contains__(self, o: object) -> bool: ...
|
||||
def __iter__(self) -> Iterator[_KT_co]: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user