From 829cdb8f90ea72a6912480a2c9f681a3899fbfeb Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Fri, 12 Jun 2020 22:03:41 +0200 Subject: [PATCH 1/2] Bump version to 0.1.4 --- wysdom/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wysdom/__version__.py b/wysdom/__version__.py index 9d91e7f..d0727ee 100644 --- a/wysdom/__version__.py +++ b/wysdom/__version__.py @@ -1,3 +1,3 @@ -VERSION = (0, 1, 3) +VERSION = (0, 1, 4) __version__ = '.'.join(map(str, VERSION)) From bc859f6a26a545f0dd8f16367504e2218d8958cb Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Fri, 12 Jun 2020 22:05:11 +0200 Subject: [PATCH 2/2] Update UserProperty so default and default_function don't set a value persistently --- features/dict.feature | 38 +++++++++++++++++++++++++---- wysdom/user_objects/UserProperty.py | 4 +-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/features/dict.feature b/features/dict.feature index 496f63d..1a794af 100644 --- a/features/dict.feature +++ b/features/dict.feature @@ -9,10 +9,10 @@ Feature: Test dictionary DOM objects "first_name": "Marge", "last_name": "Simpson", "current_address": { - "first_line": "123 Fake Street", - "second_line": "", - "city": "Springfield", - "postal_code": 58008 + "first_line": "123 Fake Street", + "second_line": "", + "city": "Springfield", + "postal_code": 58008 }, "previous_addresses": [{ "first_line": "742 Evergreen Terrace", @@ -199,4 +199,32 @@ Feature: Test dictionary DOM objects And the following statement raises ValidationError """ dict_module.Person(example_dict_input) - """ \ No newline at end of file + """ + + Scenario: Defaults should not be written as permanent values when accessed + + Given the Python module dict_module.py + When we execute the following python code: + """ + example_dict_input = { + "first_name": "Marge", + "last_name": "Simpson", + "previous_addresses": [{ + "first_line": "742 Evergreen Terrace", + "city": "Springfield", + "postal_code": 58008 + }] + } + example = dict_module.Person(example_dict_input) + original_address = example.current_address + example.previous_addresses[0] = { + "first_line": "123 Fake Street", + "city": "Springfield", + "postal_code": 58008 + } + """ + Then the following statements are true: + """ + example.current_address.first_line == "123 Fake Street" + example.previous_addresses[0].first_line == "123 Fake Street" + """ diff --git a/wysdom/user_objects/UserProperty.py b/wysdom/user_objects/UserProperty.py index 452b4cd..8333431 100644 --- a/wysdom/user_objects/UserProperty.py +++ b/wysdom/user_objects/UserProperty.py @@ -72,9 +72,9 @@ def __get__( "UserProperty is not valid as a class data descriptor") if self.name not in instance: if self.default_function: - instance[self.name] = self.default_function(instance) + return self.default_function(instance) else: - instance[self.name] = self.default + return self.default return instance[self.name] def __set__(