The Base type for complex types now has a constructor that takes attribute values as kwargs
This commit is contained in:
@@ -311,3 +311,10 @@ class TestTypes(unittest.TestCase):
|
||||
|
||||
assert B1.b2.datatype is B2, repr(B1.b2.datatype)
|
||||
assert B2.b2.datatype is B2
|
||||
|
||||
def test_base_init(self):
|
||||
class C1(types.Base):
|
||||
s = six.text_type
|
||||
|
||||
c = C1(s=six.u('test'))
|
||||
assert c.s == six.u('test')
|
||||
|
||||
@@ -490,4 +490,10 @@ class BaseMeta(type):
|
||||
if bases[0] is not object:
|
||||
cls.__registry__.register(cls)
|
||||
|
||||
Base = BaseMeta('Base', (object, ), {})
|
||||
|
||||
def Base__init__(self, **kw):
|
||||
for key, value in kw.items():
|
||||
if hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
||||
Base = BaseMeta('Base', (object, ), {'__init__': Base__init__})
|
||||
|
||||
Reference in New Issue
Block a user