Skip to content

Commit 146bc09

Browse files
author
raymond.hettinger
committed
Make ABC containers inherit as documented.
git-svn-id: http://svn.python.org/projects/python/trunk@60679 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 8846939 commit 146bc09

1 file changed

Lines changed: 5 additions & 31 deletions

File tree

Lib/_abcoll.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __subclasshook__(cls, C):
5656
Iterable.register(str)
5757

5858

59-
class Iterator:
59+
class Iterator(Iterable):
6060
__metaclass__ = ABCMeta
6161

6262
@abstractmethod
@@ -122,7 +122,7 @@ def __subclasshook__(cls, C):
122122
### SETS ###
123123

124124

125-
class Set:
125+
class Set(Sized, Iterable, Container):
126126
__metaclass__ = ABCMeta
127127

128128
"""A set is a finite, iterable container.
@@ -135,19 +135,6 @@ class Set:
135135
then the other operations will automatically follow suit.
136136
"""
137137

138-
@abstractmethod
139-
def __contains__(self, value):
140-
return False
141-
142-
@abstractmethod
143-
def __iter__(self):
144-
while False:
145-
yield None
146-
147-
@abstractmethod
148-
def __len__(self):
149-
return 0
150-
151138
def __le__(self, other):
152139
if not isinstance(other, Set):
153140
return NotImplemented
@@ -324,7 +311,7 @@ def __isub__(self, it):
324311
### MAPPINGS ###
325312

326313

327-
class Mapping:
314+
class Mapping(Sized, Iterable, Container):
328315
__metaclass__ = ABCMeta
329316

330317
@abstractmethod
@@ -345,15 +332,6 @@ def __contains__(self, key):
345332
else:
346333
return True
347334

348-
@abstractmethod
349-
def __len__(self):
350-
return 0
351-
352-
@abstractmethod
353-
def __iter__(self):
354-
while False:
355-
yield None
356-
357335
def keys(self):
358336
return KeysView(self)
359337

@@ -370,7 +348,7 @@ def __eq__(self, other):
370348
def __ne__(self, other):
371349
return not (self == other)
372350

373-
class MappingView:
351+
class MappingView(Sized):
374352
__metaclass__ = ABCMeta
375353

376354
def __init__(self, mapping):
@@ -490,7 +468,7 @@ def setdefault(self, key, default=None):
490468
### SEQUENCES ###
491469

492470

493-
class Sequence:
471+
class Sequence(Sized, Iterable, Container):
494472
__metaclass__ = ABCMeta
495473

496474
"""All the operations on a read-only sequence.
@@ -503,10 +481,6 @@ class Sequence:
503481
def __getitem__(self, index):
504482
raise IndexError
505483

506-
@abstractmethod
507-
def __len__(self):
508-
return 0
509-
510484
def __iter__(self):
511485
i = 0
512486
try:

0 commit comments

Comments
 (0)