Added view and iterator types to collections / _abcoll

I've also renamed several of the iterators to keep a consistent naming schema.
This commit is contained in:
Christian Heimes 2007-11-28 09:44:38 +00:00
parent c9543e4233
commit f83be4e3f3
7 changed files with 52 additions and 12 deletions

View File

@ -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):

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */

View File

@ -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 */