Skip to content

Commit 1ef5c86

Browse files
added itemtype properties for modeled.list class and instances
1 parent 75349f6 commit 1ef5c86

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

modeled/list.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,33 @@
1919
2020
.. moduleauthor:: Stefan Zimmermann <zimmermann.code@gmail.com>
2121
"""
22-
__all__ = ['list', 'ismodeledlistclass', 'ismodeledlist']
23-
22+
from six import with_metaclass
2423
from six.moves import builtins
2524

2625
from . import typed
2726

27+
__all__ = ['list', 'ismodeledlistclass', 'ismodeledlist']
28+
29+
30+
class meta(typed.base.type):
31+
__module__ = 'modeled'
32+
33+
@property
34+
def itemtype(cls):
35+
return cls.mtype
36+
37+
meta.__name__ = 'list.meta'
2838

29-
class list(typed.base, builtins.list):
39+
40+
class list(with_metaclass(meta, typed.base, builtins.list)):
3041
__module__ = 'modeled'
3142

32-
def __init__(self, iterable):
33-
items = iter(iterable)
43+
@property
44+
def itemtype(self):
45+
return self.mtype
46+
47+
def __init__(self, iterable=None):
48+
items = iter(iterable if iterable is not None else ())
3449
try:
3550
self.mtype
3651
except AttributeError:

0 commit comments

Comments
 (0)