Skip to content

Commit 85c36b8

Browse files
committed
Linting
1 parent 19a65fa commit 85c36b8

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/mdio/schema/v1/template_builder.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
from typing import Dict
99
from typing import List
1010
from typing import Optional
11-
from typing import Union
12-
13-
from pydantic import AwareDatetime
1411

1512
from mdio.schema.compressors import ZFP
1613
from mdio.schema.compressors import Blosc
@@ -19,7 +16,8 @@
1916
from mdio.schema.dtype import StructuredType
2017
from mdio.schema.metadata import UserAttributes
2118
from mdio.schema.v1.dataset import Dataset
22-
from mdio.schema.v1.dataset import DatasetMetadata
19+
20+
# from mdio.schema.v1.dataset import DatasetMetadata
2321
from mdio.schema.v1.template_factory import make_coordinate
2422
from mdio.schema.v1.template_factory import make_dataset
2523
from mdio.schema.v1.template_factory import make_dataset_metadata
@@ -31,6 +29,9 @@
3129
from mdio.schema.v1.variable import VariableMetadata
3230

3331

32+
# from pydantic import AwareDatetime
33+
34+
3435
class _BuilderState(Enum):
3536
"""States for the template builder."""
3637

@@ -41,14 +42,22 @@ class _BuilderState(Enum):
4142

4243

4344
class TemplateBuilder:
44-
"""Builder for creating MDIO datasets with enforced build order:
45+
"""Builder for creating MDIO datasets with enforced build order.
46+
47+
The build order is:
4548
1. Must add dimensions first via add_dimension()
4649
2. Can optionally add coordinates via add_coordinate()
4750
3. Must add variables via add_variable()
48-
4. Must call build() to create the dataset
51+
4. Must call build() to create the dataset.
4952
"""
5053

5154
def __init__(self, name: str, attributes: Optional[Dict[str, Any]] = None):
55+
"""Initialize the builder.
56+
57+
Args:
58+
name: Name of the dataset
59+
attributes: Optional attributes for the dataset
60+
"""
5261
self.name = name
5362
self.api_version = "1.0.0" # TODO: Pull from package metadata
5463
self.created_on = datetime.now(timezone.utc)
@@ -67,14 +76,19 @@ def add_dimension(
6776
data_type: ScalarType | StructuredType = ScalarType.INT32,
6877
metadata: Optional[List[AllUnits | UserAttributes]] | Dict[str, Any] = None,
6978
) -> "TemplateBuilder":
70-
"""Add a dimension. This must be called at least once before adding coordinates or variables.
79+
"""Add a dimension.
80+
81+
This must be called at least once before adding coordinates or variables.
7182
7283
Args:
7384
name: Name of the dimension
7485
size: Size of the dimension
7586
long_name: Optional long name for the dimension variable
7687
data_type: Data type for the dimension variable (defaults to INT32)
7788
metadata: Optional metadata for the dimension variable
89+
90+
Returns:
91+
self: Returns self for method chaining
7892
"""
7993
# Create the dimension
8094
dimension = make_named_dimension(name, size)
@@ -98,7 +112,7 @@ def add_coordinate(
98112
name: str = "",
99113
*,
100114
long_name: str = None,
101-
dimensions: List[NamedDimension | str] = [],
115+
dimensions: Optional[List[NamedDimension | str]] = None,
102116
data_type: ScalarType | StructuredType = ScalarType.FLOAT32,
103117
metadata: Optional[List[AllUnits | UserAttributes]] | Dict[str, Any] = None,
104118
) -> "TemplateBuilder":
@@ -110,7 +124,7 @@ def add_coordinate(
110124

111125
if name == "":
112126
name = f"coord_{len(self._coordinates)}"
113-
if dimensions == []:
127+
if dimensions is None:
114128
dimensions = self._dimensions
115129
if isinstance(metadata, dict):
116130
metadata = [metadata]
@@ -121,7 +135,7 @@ def add_coordinate(
121135
if isinstance(dim, str):
122136
dim_obj = next((d for d in self._dimensions if d.name == dim), None)
123137
if dim_obj is None:
124-
raise ValueError(f"Dimension '{dim}' not found")
138+
raise ValueError(f"Dimension {dim!r} not found")
125139
dim_objects.append(dim_obj)
126140
else:
127141
dim_objects.append(dim)
@@ -143,7 +157,7 @@ def add_variable(
143157
name: str = "",
144158
*,
145159
long_name: str = None,
146-
dimensions: List[NamedDimension | str] = [],
160+
dimensions: Optional[List[NamedDimension | str]] = None,
147161
data_type: ScalarType | StructuredType = ScalarType.FLOAT32,
148162
compressor: Blosc | ZFP | None = None,
149163
coordinates: Optional[List[Coordinate | str]] = None,
@@ -156,7 +170,7 @@ def add_variable(
156170
if name == "":
157171
name = f"var_{self._unnamed_variable_counter}"
158172
self._unnamed_variable_counter += 1
159-
if dimensions == []:
173+
if dimensions is None:
160174
dimensions = self._dimensions
161175

162176
# Convert string dimension names to NamedDimension objects
@@ -165,7 +179,7 @@ def add_variable(
165179
if isinstance(dim, str):
166180
dim_obj = next((d for d in self._dimensions if d.name == dim), None)
167181
if dim_obj is None:
168-
raise ValueError(f"Dimension '{dim}' not found")
182+
raise ValueError(f"Dimension {dim!r} not found")
169183
dim_objects.append(dim_obj)
170184
else:
171185
dim_objects.append(dim)

0 commit comments

Comments
 (0)