Commit b4292c1c authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Removed unnecessary reflection.

parent 2a091d61
......@@ -19,6 +19,21 @@ import sys
__module__ = sys.modules[__name__]
MObjectBound = TypeVar('MObjectBound', bound='MObject')
- Is the reflection interface really necessary? The ideas come from a compiled static
language (Java). In Python the non reflective interface can always be dynamically
generated and then reflectively used through pythons build in reflection mechanisms
(e.g. getattr, hasattr, ...)
- Subsection creation would be most fluent with: ``system = System(m_parent=run)``
- Specialized data entry methods would require refl. interface:
- m_add_array_values
- m_add
# Reflection
......@@ -94,22 +109,12 @@ class MObject(metaclass=MObjectMeta):
return section_instance
def m_set(self, name: str, value: Any):
self.m_data[name] = value
def m_add(self, name: str, value: Any):
values = self.m_data.setdefault(name, [])
def m_get(self, name: str) -> Any:
return self.m_data[name]
except KeyError:
return self.m_section.attributes[name].default
def m_delete(self, name: str):
del self.m_data[name]
def m_add_array_values(self, definition: Union[str, 'Quantity'], values, offset: int):
def m_to_dict(self):
......@@ -160,13 +165,13 @@ class Quantity(MObject):
default = property(lambda self: None)
def __get__(self, obj, type=None):
return obj.m_get(self.__name)
return obj.m_data[self.__name]
def __set__(self, obj, value):
obj.m_set(self.__name, value)
obj.m_data[self.__name] = value
def __delete__(self, obj):
del obj.m_data[self.__name]
class Section(MObject):
......@@ -26,22 +26,6 @@ class TestM3:
assert Quantity.m_section.parent == Section.m_section
class TestReflection:
def test_m_get_success(self):
assert Section.m_section.m_get('name') == 'Section'
def test_m_get_fail(self):
assert False
except KeyError:
def test_m_set_success(self):
Section.m_section.m_set('name', 'newname')
assert Section.m_section.m_get('name') == 'newname'
class TestPureReflection:
def test_instantiation(self):
......@@ -51,8 +35,8 @@ class TestPureReflection:
obj = MObject(m_section=test_section_def)
assert == 'TestSection'
# FIXME assert obj.m_get('test_quantity') is None
obj.m_set('test_quantity', 'test_value')
assert obj.m_get('test_quantity') == 'test_value'
setattr(obj, 'test_quantity', 'test_value')
assert getattr(obj, 'test_quantity') == 'test_value'
class Run(MObject):
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