sh_cpl/src/cpl_query/extension/list.py

19 lines
513 B
Python
Raw Normal View History

2021-07-26 15:52:27 +02:00
from .._extension.iterable import Iterable
2021-07-25 19:15:02 +02:00
2021-07-26 15:21:57 +02:00
class List(Iterable):
2021-07-25 19:15:02 +02:00
2021-07-26 15:21:57 +02:00
def __init__(self, t: type = None, values: list = None):
Iterable.__init__(self)
2021-07-25 19:15:02 +02:00
2021-07-26 15:21:57 +02:00
self._type = t
2021-07-25 19:15:02 +02:00
2021-07-26 15:21:57 +02:00
if values is not None:
self.extend(values)
2021-07-26 15:48:42 +02:00
def append(self, __object: object) -> None:
if self._type is not None and type(__object) != self._type and not isinstance(type(__object), self._type):
raise Exception(f'Unexpected type: {type(__object)}')
super().append(__object)