Skip to content

Commit dfa7581

Browse files
committed
Add central registry for classes; add metaclass for DictSerializable
1 parent 363500b commit dfa7581

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+202
-226
lines changed

gemd/builders/tests/test_builders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from typing import Union
1717

1818

19-
class UnsupportedBounds(BaseBounds):
19+
class UnsupportedBounds(BaseBounds, typ="unsupported_bounds"):
2020
"""Dummy object to test Bounds type checking."""
2121

2222
def contains(self, bounds): # pragma: no cover
@@ -32,15 +32,15 @@ def update(self, *others: Union["BaseBounds", "BaseValue"]): # pragma: no cover
3232
pass
3333

3434

35-
class UnsupportedAttribute(BaseAttribute):
35+
class UnsupportedAttribute(BaseAttribute, typ="unsupported_attribute"):
3636
"""Dummy object to test Attribute type checking."""
3737

3838
def _template_type(self): # pragma: no cover
3939
"""Only here to satisfy abstract method."""
4040
return str
4141

4242

43-
class UnsupportedAttributeTemplate(AttributeTemplate):
43+
class UnsupportedAttributeTemplate(AttributeTemplate, typ="unsupported_template"):
4444
"""Dummy object to test Attribute type checking."""
4545

4646

gemd/entity/attribute/condition.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Type
55

66

7-
class Condition(BaseAttribute):
7+
class Condition(BaseAttribute, typ="condition"):
88
"""
99
Condition of a property, process, or measurement.
1010
@@ -31,8 +31,6 @@ class Condition(BaseAttribute):
3131
3232
"""
3333

34-
typ = "condition"
35-
3634
@staticmethod
3735
def _template_type() -> Type:
3836
return ConditionTemplate

gemd/entity/attribute/parameter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Type
55

66

7-
class Parameter(BaseAttribute):
7+
class Parameter(BaseAttribute, typ="parameter"):
88
"""
99
Parameter of a process or measurement.
1010
@@ -32,8 +32,6 @@ class Parameter(BaseAttribute):
3232
3333
"""
3434

35-
typ = "parameter"
36-
3735
@staticmethod
3836
def _template_type() -> Type:
3937
return ParameterTemplate

gemd/entity/attribute/property.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Type
55

66

7-
class Property(BaseAttribute):
7+
class Property(BaseAttribute, typ="property"):
88
"""
99
Property of a material, measured in a MeasurementRun or specified in a MaterialSpec.
1010
@@ -31,8 +31,6 @@ class Property(BaseAttribute):
3131
3232
"""
3333

34-
typ = "property"
35-
3634
@staticmethod
3735
def _template_type() -> Type:
3836
return PropertyTemplate

gemd/entity/attribute/property_and_conditions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from typing import Optional, Union, Iterable, List
1010

1111

12-
class PropertyAndConditions(DictSerializable):
12+
class PropertyAndConditions(DictSerializable, typ="property_and_conditions"):
1313
"""
1414
A property and the conditions under which that property was determined.
1515
@@ -24,8 +24,6 @@ class PropertyAndConditions(DictSerializable):
2424
2525
"""
2626

27-
typ = "property_and_conditions"
28-
2927
def __init__(self,
3028
property: Property = None,
3129
conditions: Union[Iterable[Condition], Condition] = None):

gemd/entity/base_entity.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ class BaseEntity(DictSerializable):
2424
2525
"""
2626

27-
typ = "base"
28-
2927
def __init__(self, uids: Mapping[str, str], tags: Iterable[str]):
3028
self._tags = None
3129
self.tags = tags

gemd/entity/bounds/categorical_bounds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Union, Set, Optional, Iterable
66

77

8-
class CategoricalBounds(BaseBounds):
8+
class CategoricalBounds(BaseBounds, typ="categorical_bounds"):
99
"""
1010
Categorical bounds, parameterized by a set of string-valued category labels.
1111
@@ -16,8 +16,6 @@ class CategoricalBounds(BaseBounds):
1616
1717
"""
1818

19-
typ = "categorical_bounds"
20-
2119
def __init__(self, categories: Optional[Iterable[str]] = None):
2220
self._categories = None
2321
self.categories = categories

gemd/entity/bounds/composition_bounds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Union
66

77

8-
class CompositionBounds(BaseBounds):
8+
class CompositionBounds(BaseBounds, typ="composition_bounds"):
99
"""
1010
Composition bounds, parameterized by a set of string-valued category labels.
1111
@@ -16,8 +16,6 @@ class CompositionBounds(BaseBounds):
1616
1717
"""
1818

19-
typ = "composition_bounds"
20-
2119
def __init__(self, components=None):
2220
self._components = None
2321
self.components = components

gemd/entity/bounds/integer_bounds.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Union
55

66

7-
class IntegerBounds(BaseBounds):
7+
class IntegerBounds(BaseBounds, typ="integer_bounds"):
88
"""
99
Bounded subset of the integers, parameterized by a lower and upper bound.
1010
@@ -17,8 +17,6 @@ class IntegerBounds(BaseBounds):
1717
1818
"""
1919

20-
typ = "integer_bounds"
21-
2220
def __init__(self, lower_bound=None, upper_bound=None):
2321
self.lower_bound = lower_bound
2422
self.upper_bound = upper_bound

gemd/entity/bounds/molecular_structure_bounds.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@
88
from typing import Union
99

1010

11-
class MolecularStructureBounds(BaseBounds):
11+
class MolecularStructureBounds(BaseBounds, typ="molecular_structure_bounds"):
1212
"""Molecular bounds, with no component or substructural restrictions (yet)."""
1313

14-
typ = "molecular_structure_bounds"
15-
16-
def __init__(self):
17-
pass
18-
1914
def contains(self, bounds: Union[BaseBounds, "BaseValue"]) -> bool:
2015
"""
2116
Check if another bounds or value object is contained by this bounds.

0 commit comments

Comments
 (0)