Skip to content

Commit

Permalink
Add variable inheritance in declarations (#155)
Browse files Browse the repository at this point in the history
* Format and improve error handling

* Allow inheritance in variable declarations
Fixes #154

* Changelog entry
  • Loading branch information
nikhilwoodruff authored Feb 8, 2024
1 parent 9a47038 commit 0ac5816
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
added:
- Variable inheritance in declarations.
15 changes: 15 additions & 0 deletions policyengine_core/variables/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ def __init__(self, baseline_variable=None):
for name, value in self.__class__.__dict__.items()
if not name.startswith("__")
}

# Allow inheritance for some properties
INHERITED_ALLOWED_PROPERTIES = (
"label",
"value_type",
"entity",
"definition_period",
)

for property_name in INHERITED_ALLOWED_PROPERTIES:
if not attr.get(property_name) and property_name in dir(
self.__class__
):
attr[property_name] = getattr(self, property_name)

self.baseline_variable = baseline_variable
self.value_type = self.set(
attr,
Expand Down

0 comments on commit 0ac5816

Please sign in to comment.