Add sets and iterable/iterator

This commit is contained in:
Claude
2015-12-30 19:32:31 +01:00
parent 85023a22aa
commit e688a498ab
2 changed files with 62 additions and 1 deletions
+30 -1
View File
@@ -7,7 +7,19 @@ from collections import abc
def factory(typing_name, indextype):
class Sequence(abc.Sequence):
class Iterable(abc.Iterable):
def __iter__(self):
yield indextype()
class Iterator(Iterable, abc.Iterator):
def next(self):
""" needed for python 2 """
return self.__next__()
def __next__(self):
return indextype()
class Sequence(Iterable, abc.Sequence):
def __getitem__(self, index: int):
return indextype()
@@ -15,12 +27,29 @@ def factory(typing_name, indextype):
def __setitem__(self, index: int, value: indextype):
pass
def __delitem__(self, index: int, value: indextype):
pass
class List(MutableSequence, list):
pass
class AbstractSet(Iterable, abc.Set):
pass
class MutableSet(AbstractSet, abc.MutableSet):
def add(item: indextype):
pass
def discard(item: indextype):
pass
dct = {
"Sequence": Sequence,
"MutableSequence": MutableSequence,
"List": List,
"Iterable": Iterable,
"Iterator": Iterator,
"AbstractSet": AbstractSet,
"MutableSet": MutableSet,
}
return dct[typing_name]