This commit is contained in:
Markus Padourek 2016-08-08 08:47:57 +00:00 committed by GitHub
commit a4f6bc08a8
2 changed files with 12 additions and 1 deletions

View File

@ -80,7 +80,7 @@ class ObjectType(six.with_metaclass(ObjectTypeMeta, FieldsClassType)):
if kwargs: if kwargs:
for prop in list(kwargs): for prop in list(kwargs):
try: try:
if isinstance(getattr(self.__class__, prop), property): if isinstance(getattr(self.__class__, prop), property) or prop.startswith('_'):
setattr(self, prop, kwargs.pop(prop)) setattr(self, prop, kwargs.pop(prop))
except AttributeError: except AttributeError:
pass pass

View File

@ -55,6 +55,17 @@ def test_object_type_set_properties():
assert h.write_prop == 'custom' assert h.write_prop == 'custom'
def test_object_type_set_private_attributes():
class Human(ObjectType):
_private_state = None
h = Human(_private_state='custom')
assert h._private_state == 'custom'
with raises(TypeError):
Human(_other_private_state='My name')
def test_object_type_container_invalid_kwarg(): def test_object_type_container_invalid_kwarg():
class Human(ObjectType): class Human(ObjectType):
name = String() name = String()