diff --git a/.pycodestyle.ini b/.pycodestyle.ini index 85baad5..2326271 100644 --- a/.pycodestyle.ini +++ b/.pycodestyle.ini @@ -3,6 +3,7 @@ # E401 multiple imports on one line (checked by PyLint) # E402 module level import not at top of file (checked by PyLint) # E501: line too long (checked by PyLint) +# E701: multiple statements on one line (used to shorten test syntax) # E711: comparison to None (used to improve test style) # E712: comparison to True (used to improve test style) -ignore = E401,E402,E501,E711,E712 +ignore = E401,E402,E501,E701,E711,E712 diff --git a/CHANGELOG.md b/CHANGELOG.md index 6451976..ebd18f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Removed warnings about calling save/load unnecessarily. - Allow keyword arguments to be passed to class construction via `new` and `find` utilities. +- Fixed missing attributes added in `__init__` on `AttributeDictionary`. ## 1.3 (2017/01/24) diff --git a/yorm/__init__.py b/yorm/__init__.py index 18a850f..5b67c6d 100644 --- a/yorm/__init__.py +++ b/yorm/__init__.py @@ -8,4 +8,4 @@ from .mixins import ModelMixin __project__ = 'YORM' -__version__ = '1.4dev4' +__version__ = '1.4dev5' diff --git a/yorm/tests/test_types_extended.py b/yorm/tests/test_types_extended.py index 48d0381..a883f91 100644 --- a/yorm/tests/test_types_extended.py +++ b/yorm/tests/test_types_extended.py @@ -54,14 +54,21 @@ def it_converts_correctly(value, data): def describe_attribute_dictionary(): - @attr(var1=Integer) - @attr(var2=String) - class SampleAttributeDictionary(AttributeDictionary): - """Sample attribute dictionary.""" + @pytest.fixture + def cls(): + @attr(var1=Integer) + @attr(var2=String) + class SampleAttributeDictionary(AttributeDictionary): pass + return SampleAttributeDictionary @pytest.fixture - def converter(): - return SampleAttributeDictionary() + def cls_with_init(): + @attr(var1=Integer) + class SampleAttributeDictionaryWithInit(AttributeDictionary): + def __init__(self, *args, var2="2", **kwargs): + super().__init__(*args, **kwargs) + self.var2 = var2 + return SampleAttributeDictionaryWithInit def it_cannot_be_used_directly(): with expect.raises(NotImplementedError): @@ -69,8 +76,20 @@ def it_cannot_be_used_directly(): with expect.raises(NotImplementedError): AttributeDictionary.to_data(None) - def it_has_keys_available_as_attributes(converter): + def it_has_keys_available_as_attributes(cls): + converter = cls() + value = converter.to_value({'var1': 1, 'var2': "2"}) + + expect(value.var1) == 1 + expect(value.var2) == "2" + + def it_adds_extra_attributes_from_init(cls_with_init): + converter = cls_with_init() + + value = converter.to_value({'var1': 1}) + print(value.__dict__) + expect(value.var1) == 1 expect(value.var2) == "2" diff --git a/yorm/types/extended.py b/yorm/types/extended.py index 7d47a4d..ce5fca6 100644 --- a/yorm/types/extended.py +++ b/yorm/types/extended.py @@ -145,9 +145,7 @@ def create_default(cls): msg = "AttributeDictionary class must be subclassed to use" raise NotImplementedError(msg) - obj = cls.__new__(cls) - obj.__dict__ = obj - return obj + return cls() class SortedList(List):