-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Stop inheriting Sized in collection ABCs #2658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e3750e
Stop inheriting Sized in collection ABCs
8739644
Fix tests -- MappingView has a *concrete* __len__ implementation
5ccb8bd
Put _Collection back in Sequence, remove unneeded __len__ from it and…
4f78791
Put MappingView first in ItemsView and KeysView
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,13 +235,20 @@ 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]): | ||
| class Sequence(Iterable[_T_co], Container[_T_co], Reversible[_T_co], Generic[_T_co]): | ||
|
||
| @overload | ||
| @abstractmethod | ||
| def __getitem__(self, i: int) -> _T_co: ... | ||
|
|
@@ -257,6 +264,9 @@ class Sequence(_Collection[_T_co], Reversible[_T_co], Generic[_T_co]): | |
| def __contains__(self, x: object) -> bool: ... | ||
| def __iter__(self) -> Iterator[_T_co]: ... | ||
| def __reversed__(self) -> Iterator[_T_co]: ... | ||
| # Implement Sized (but don't have it as a base class). | ||
| @abstractmethod | ||
| def __len__(self) -> int: ... | ||
|
|
||
| class MutableSequence(Sequence[_T], Generic[_T]): | ||
| @abstractmethod | ||
|
|
@@ -302,6 +312,9 @@ class AbstractSet(_Collection[_T_co], Generic[_T_co]): | |
| def __xor__(self, s: AbstractSet[_T]) -> AbstractSet[Union[_T_co, _T]]: ... | ||
| # TODO: Argument can be a more general ABC? | ||
| def isdisjoint(self, s: AbstractSet[Any]) -> bool: ... | ||
| # Implement Sized (but don't have it as a base class). | ||
| @abstractmethod | ||
| def __len__(self) -> int: ... | ||
gvanrossum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| class MutableSet(AbstractSet[_T], Generic[_T]): | ||
| @abstractmethod | ||
|
|
@@ -317,7 +330,10 @@ 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: ... | ||
| # Implement Sized (but don't have it as a base class). | ||
| @abstractmethod | ||
gvanrossum marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def __len__(self) -> int: ... | ||
|
|
||
| class ItemsView(AbstractSet[Tuple[_KT_co, _VT_co]], MappingView, Generic[_KT_co, _VT_co]): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.