Make ABC containers inherit as documented.

This commit is contained in:
Raymond Hettinger 2008-02-09 01:18:42 +00:00
parent 7e33663ec4
commit c2bc0d17e8
1 changed files with 5 additions and 31 deletions

View File

@ -56,7 +56,7 @@ class Iterable:
Iterable.register(str) Iterable.register(str)
class Iterator: class Iterator(Iterable):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
@abstractmethod @abstractmethod
@ -122,7 +122,7 @@ class Callable:
### SETS ### ### SETS ###
class Set: class Set(Sized, Iterable, Container):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
"""A set is a finite, iterable container. """A set is a finite, iterable container.
@ -135,19 +135,6 @@ class Set:
then the other operations will automatically follow suit. then the other operations will automatically follow suit.
""" """
@abstractmethod
def __contains__(self, value):
return False
@abstractmethod
def __iter__(self):
while False:
yield None
@abstractmethod
def __len__(self):
return 0
def __le__(self, other): def __le__(self, other):
if not isinstance(other, Set): if not isinstance(other, Set):
return NotImplemented return NotImplemented
@ -324,7 +311,7 @@ MutableSet.register(set)
### MAPPINGS ### ### MAPPINGS ###
class Mapping: class Mapping(Sized, Iterable, Container):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
@abstractmethod @abstractmethod
@ -345,15 +332,6 @@ class Mapping:
else: else:
return True return True
@abstractmethod
def __len__(self):
return 0
@abstractmethod
def __iter__(self):
while False:
yield None
def keys(self): def keys(self):
return KeysView(self) return KeysView(self)
@ -370,7 +348,7 @@ class Mapping:
def __ne__(self, other): def __ne__(self, other):
return not (self == other) return not (self == other)
class MappingView: class MappingView(Sized):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
def __init__(self, mapping): def __init__(self, mapping):
@ -490,7 +468,7 @@ MutableMapping.register(dict)
### SEQUENCES ### ### SEQUENCES ###
class Sequence: class Sequence(Sized, Iterable, Container):
__metaclass__ = ABCMeta __metaclass__ = ABCMeta
"""All the operations on a read-only sequence. """All the operations on a read-only sequence.
@ -503,10 +481,6 @@ class Sequence:
def __getitem__(self, index): def __getitem__(self, index):
raise IndexError raise IndexError
@abstractmethod
def __len__(self):
return 0
def __iter__(self): def __iter__(self):
i = 0 i = 0
try: try: