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

Minor code layout fixes.

parent 595bc21e
...@@ -134,6 +134,7 @@ See the reference of classes :class:`Section` and :class:`Quantities` for detail ...@@ -134,6 +134,7 @@ See the reference of classes :class:`Section` and :class:`Quantities` for detail
.. autoclass:: Quantity .. autoclass:: Quantity
""" """
# TODO event mechanism
# TODO validation and constraints # TODO validation and constraints
from typing import Type, TypeVar, Union, Tuple, Iterable, List, Any, Dict, Set, \ from typing import Type, TypeVar, Union, Tuple, Iterable, List, Any, Dict, Set, \
...@@ -160,6 +161,8 @@ MSectionBound = TypeVar('MSectionBound', bound='MSection') ...@@ -160,6 +161,8 @@ MSectionBound = TypeVar('MSectionBound', bound='MSection')
T = TypeVar('T') T = TypeVar('T')
# Metainfo errors
class MetainfoError(Exception): class MetainfoError(Exception):
""" An error within the definition for metainfo data. """ """ An error within the definition for metainfo data. """
pass pass
...@@ -170,7 +173,7 @@ class DeriveError(MetainfoError): ...@@ -170,7 +173,7 @@ class DeriveError(MetainfoError):
pass pass
# Reflection # Metainfo quantity data types
class Enum(list): class Enum(list):
""" Allows to define str types with values limited to a pre-set list of possible values. """ """ Allows to define str types with values limited to a pre-set list of possible values. """
...@@ -256,6 +259,10 @@ class __Unit(DataType): ...@@ -256,6 +259,10 @@ class __Unit(DataType):
return units.parse_units(value) return units.parse_units(value)
units = UnitRegistry()
""" The default pint unit registry that should be used to give units to quantity definitions. """
class __Callable(DataType): class __Callable(DataType):
def serialize(self, section, quantity_def: 'Quantity', value): def serialize(self, section, quantity_def: 'Quantity', value):
raise MetainfoError('Callables cannot be serialized') raise MetainfoError('Callables cannot be serialized')
...@@ -423,6 +430,8 @@ Callable = __Callable() ...@@ -423,6 +430,8 @@ Callable = __Callable()
Datetime = __Datetime() Datetime = __Datetime()
# Metainfo data storage and reflection interface
class MObjectMeta(type): class MObjectMeta(type):
def __new__(self, cls_name, bases, dct): def __new__(self, cls_name, bases, dct):
...@@ -1236,6 +1245,8 @@ class cached_property: ...@@ -1236,6 +1245,8 @@ class cached_property:
return value return value
# Metainfo M3 (i.e. definitions of definitions)
class Definition(MSection): class Definition(MSection):
__all_definitions: Dict[Type[MSection], List[MSection]] = {} __all_definitions: Dict[Type[MSection], List[MSection]] = {}
...@@ -1624,6 +1635,3 @@ Category.__init_cls__() ...@@ -1624,6 +1635,3 @@ Category.__init_cls__()
Section.__init_cls__() Section.__init_cls__()
SubSection.__init_cls__() SubSection.__init_cls__()
Quantity.__init_cls__() Quantity.__init_cls__()
units = UnitRegistry()
""" The default pint unit registry that should be used to give units to quantity definitions. """
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