diff options
author | Christian Heimes <christian@cheimes.de> | 2007-11-28 09:44:38 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-11-28 09:44:38 (GMT) |
commit | f83be4e3f353c4cfb53a22793dd1394797988c30 (patch) | |
tree | f3a4c1535a6b18cca165f1b24f1fe51f6c49eef3 | |
parent | c9543e42330e5f339d6419eba6a8c5a61a39aeca (diff) | |
download | cpython-f83be4e3f353c4cfb53a22793dd1394797988c30.zip cpython-f83be4e3f353c4cfb53a22793dd1394797988c30.tar.gz cpython-f83be4e3f353c4cfb53a22793dd1394797988c30.tar.bz2 |
Added view and iterator types to collections / _abcoll
I've also renamed several of the iterators to keep a consistent naming schema.
-rw-r--r-- | Lib/_abcoll.py | 46 | ||||
-rw-r--r-- | Objects/dictobject.c | 6 | ||||
-rw-r--r-- | Objects/iterobject.c | 2 | ||||
-rw-r--r-- | Objects/listobject.c | 4 | ||||
-rw-r--r-- | Objects/rangeobject.c | 2 | ||||
-rw-r--r-- | Objects/setobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 2 |
7 files changed, 52 insertions, 12 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index 6363de9..d91c010 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -17,8 +17,35 @@ __all__ = ["Hashable", "Iterable", "Iterator", "MappingView", "KeysView", "ItemsView", "ValuesView", "Sequence", "MutableSequence", "ByteString", + "bytearray_iterator", "bytes_iterator", "dict_itemiterator", + "dict_items", "dict_keyiterator", "dict_keys", + "dict_valueiterator", "dict_values", "list_iterator", + "list_reverseiterator", "range_iterator", "set_iterator", + "str_iterator", "tuple_iterator", "zip_iterator", ] + +### collection related types which are not exposed through builtin ### +## iterators ## +bytes_iterator = type(iter(b'')) +bytearray_iterator = type(iter(bytearray())) +#callable_iterator = ??? +dict_keyiterator = type(iter({}.keys())) +dict_valueiterator = type(iter({}.values())) +dict_itemiterator = type(iter({}.items())) +list_iterator = type(iter([])) +list_reverseiterator = type(iter(reversed([]))) +range_iterator = type(iter(range(0))) +set_iterator = type(iter(set())) +str_iterator = type(iter("")) +tuple_iterator = type(iter(())) +zip_iterator = type(iter(zip())) +## views ## +dict_keys = type({}.keys()) +dict_values = type({}.values()) +dict_items = type({}.items()) + + ### ONE-TRICK PONIES ### class Hashable(metaclass=ABCMeta): @@ -69,6 +96,19 @@ class Iterator(metaclass=ABCMeta): return True return NotImplemented +Iterator.register(bytes_iterator) +Iterator.register(bytearray_iterator) +#Iterator.register(callable_iterator) +Iterator.register(dict_keyiterator) +Iterator.register(dict_valueiterator) +Iterator.register(dict_itemiterator) +Iterator.register(list_iterator) +Iterator.register(list_reverseiterator) +Iterator.register(range_iterator) +Iterator.register(set_iterator) +Iterator.register(str_iterator) +Iterator.register(tuple_iterator) +Iterator.register(zip_iterator) class Sized(metaclass=ABCMeta): @@ -349,7 +389,7 @@ class KeysView(MappingView, Set): for key in self._mapping: yield key -KeysView.register(type({}.keys())) +KeysView.register(dict_keys) class ItemsView(MappingView, Set): @@ -367,7 +407,7 @@ class ItemsView(MappingView, Set): for key in self._mapping: yield (key, self._mapping[key]) -ItemsView.register(type({}.items())) +ItemsView.register(dict_items) class ValuesView(MappingView): @@ -382,7 +422,7 @@ class ValuesView(MappingView): for key in self._mapping: yield self._mapping[key] -ValuesView.register(type({}.values())) +ValuesView.register(dict_values) class MutableMapping(Mapping): diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 7bff7d8..b849f57 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2148,7 +2148,7 @@ fail: PyTypeObject PyDictIterKey_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dictionary-keyiterator", /* tp_name */ + "dict_keyiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -2220,7 +2220,7 @@ fail: PyTypeObject PyDictIterValue_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dictionary-valueiterator", /* tp_name */ + "dict_valueiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -2306,7 +2306,7 @@ fail: PyTypeObject PyDictIterItem_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "dictionary-itemiterator", /* tp_name */ + "dict_itemiterator", /* tp_name */ sizeof(dictiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 32b9f94..ce9c661 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -369,7 +369,7 @@ zipiter_next(zipiterobject *zit) static PyTypeObject PyZipIter_Type = { PyVarObject_HEAD_INIT(0, 0) - "zipiterator", /* tp_name */ + "zip_iterator", /* tp_name */ sizeof(zipiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/listobject.c b/Objects/listobject.c index 5df40fa..1d82e35 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2726,7 +2726,7 @@ static PyMethodDef listiter_methods[] = { PyTypeObject PyListIter_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "listiterator", /* tp_name */ + "list_iterator", /* tp_name */ sizeof(listiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ @@ -2848,7 +2848,7 @@ static PySequenceMethods listreviter_as_sequence = { PyTypeObject PyListRevIter_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "listreverseiterator", /* tp_name */ + "list_reverseiterator", /* tp_name */ sizeof(listreviterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/rangeobject.c b/Objects/rangeobject.c index 0bb3e7b..d1c959a 100644 --- a/Objects/rangeobject.c +++ b/Objects/rangeobject.c @@ -369,7 +369,7 @@ static PyMethodDef rangeiter_methods[] = { PyTypeObject Pyrangeiter_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "rangeiterator", /* tp_name */ + "range_iterator", /* tp_name */ sizeof(rangeiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/setobject.c b/Objects/setobject.c index d85a28d..e4e7780 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -851,7 +851,7 @@ fail: static PyTypeObject PySetIter_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "setiterator", /* tp_name */ + "set_iterator", /* tp_name */ sizeof(setiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 205576f..26349ef 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9263,7 +9263,7 @@ static PyMethodDef unicodeiter_methods[] = { PyTypeObject PyUnicodeIter_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "unicode_iterator", /* tp_name */ + "str_iterator", /* tp_name */ sizeof(unicodeiterobject), /* tp_basicsize */ 0, /* tp_itemsize */ /* methods */ |