Skip to content

Commit 558bf54

Browse files
committed
#156 Update array and scalar specifications
1 parent d71f9bc commit 558bf54

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

xarray_dataclasses/specs.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ class ArraySpec:
4545
role: Literal["coord", "data"]
4646
"""Role of the array."""
4747

48-
default: Any
49-
"""Default value of the array."""
50-
51-
dims: Dims = ()
48+
dims: Dims
5249
"""Dimensions of the array."""
5350

54-
dtype: Optional[AnyDType] = None
51+
dtype: Optional[AnyDType]
5552
"""Data type of the array."""
5653

54+
default: Any
55+
"""Default value of the array."""
56+
5757
origin: Optional[Type[DataClass[Any]]] = None
5858
"""Dataclass as origins of name, dims, and dtype."""
5959

@@ -85,12 +85,12 @@ class ScalarSpec:
8585
role: Literal["attr", "name"]
8686
"""Role of the scalar."""
8787

88+
type: Any
89+
"""Type (hint) of the scalar."""
90+
8891
default: Any
8992
"""Default value of the scalar."""
9093

91-
dtype: Any
92-
"""Data type of the scalar."""
93-
9494

9595
class SpecDict(Dict[str, AnySpec]):
9696
"""Dictionary of any specifications."""
@@ -178,22 +178,24 @@ def get_spec(field: AnyField) -> Optional[AnySpec]:
178178
return ArraySpec(
179179
name=name,
180180
role=role.value,
181+
dims=(), # dummy
182+
dtype=None, # dummy
181183
default=field.default,
182184
origin=get_dataclass(field.type),
183185
)
184186
except TypeError:
185187
return ArraySpec(
186188
name=name,
187189
role=role.value,
188-
default=field.default,
189190
dims=get_dims(field.type),
190191
dtype=get_dtype(field.type),
192+
default=field.default,
191193
)
192194

193195
if role is Role.ATTR or role is Role.NAME:
194196
return ScalarSpec(
195197
name=name,
196198
role=role.value,
199+
type=get_annotated(field.type),
197200
default=field.default,
198-
dtype=get_annotated(field.type),
199201
)

0 commit comments

Comments
 (0)