Commit 1dc52162 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added automatic defaults for primitive types in metainfo.

parent ff67c004
......@@ -1791,6 +1791,15 @@ class Quantity(Property):
if self.synonym_for is not None:
self._synonym = self.m_parent.all_quantities[self.synonym_for]
if self.type == int and self.is_scalar and self.default is None:
self.default = 0
if self.type == float and self.is_scalar and self.default is None:
self.default = 0.0
if self.type == bool and self.is_scalar and self.default is None:
self.default = False
# replace the quantity implementation with an optimized version for the most
# primitive quantities if applicable
is_primitive = not self.synonym_for and not self.derived
......
......@@ -592,6 +592,16 @@ class TestM1:
assert copy.systems[0].m_parent_index == 0
assert copy.systems[0].m_parent_sub_section is run.systems[0].m_parent_sub_section
def test_default_defaults(self):
class TestSection(MSection):
int_quantity = Quantity(type=int)
float_quantity = Quantity(type=float)
bool_quantity = Quantity(type=bool)
section = TestSection()
assert section.int_quantity == 0
assert section.float_quantity == 0.0
assert section.bool_quantity == False
class TestDatatypes:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment