@@ -90,16 +90,22 @@ def _field_attr_sort_key(item) -> int:
9090 return 8
9191
9292
93- _SCALAR_TYPES = {
93+ FormatVersion = Literal [1 , 2 ]
94+ """DFN format version number."""
95+
96+
97+ FieldType = Literal [
9498 "keyword" ,
9599 "integer" ,
96100 "double precision" ,
97101 "string" ,
98- }
102+ "record" ,
103+ "recarray" ,
104+ "keystring" ,
105+ ]
99106
100107
101- DfnFmtVersion = Literal [1 , 2 ]
102- """DFN format version number."""
108+ _SCALAR_TYPES = FieldType .__args__ [:4 ]
103109
104110
105111Dfns = dict [str , "Dfn" ]
@@ -110,7 +116,7 @@ class Field(TypedDict):
110116 """A field specification."""
111117
112118 name : str
113- type : str
119+ type : FieldType
114120 shape : Any | None = None
115121 block : str | None = None
116122 default : Any | None = None
@@ -301,7 +307,7 @@ def _load(field) -> Field:
301307 fkeys [_name ] = ref
302308
303309 def _item () -> Field :
304- """Load a list's item."""
310+ """Load list item."""
305311
306312 item_names = _type .split ()[1 :]
307313 item_types = [
@@ -342,7 +348,9 @@ def _item() -> Field:
342348 first = next (iter (fields .values ()))
343349 single = len (fields ) == 1
344350 item_type = (
345- "union" if single and "keystring" in first ["type" ] else "record"
351+ "keystring"
352+ if single and "keystring" in first ["type" ]
353+ else "record"
346354 )
347355 return Field (
348356 name = first ["name" ] if single else _name ,
@@ -356,7 +364,7 @@ def _item() -> Field:
356364 )
357365
358366 def _choices () -> Fields :
359- """Load a union's choices."""
367+ """Load keystring ( union) choices."""
360368 names = _type .split ()[1 :]
361369 return {
362370 v ["name" ]: _convert_field (v )
@@ -365,7 +373,7 @@ def _choices() -> Fields:
365373 }
366374
367375 def _fields () -> Fields :
368- """Load a record's fields."""
376+ """Load record fields."""
369377 names = _type .split ()[1 :]
370378 fields = {}
371379 for name in names :
@@ -390,11 +398,11 @@ def _fields() -> Fields:
390398
391399 if _type .startswith ("recarray" ):
392400 var_ ["item" ] = _item ()
393- var_ ["type" ] = "list "
401+ var_ ["type" ] = "recarray "
394402
395403 elif _type .startswith ("keystring" ):
396404 var_ ["choices" ] = _choices ()
397- var_ ["type" ] = "union "
405+ var_ ["type" ] = "keystring "
398406
399407 elif _type .startswith ("record" ):
400408 var_ ["fields" ] = _fields ()
@@ -548,7 +556,7 @@ def load(
548556 cls ,
549557 f ,
550558 name : str | None = None ,
551- version : DfnFmtVersion = 1 ,
559+ version : FormatVersion = 1 ,
552560 ** kwargs ,
553561 ) -> "Dfn" :
554562 """
@@ -608,7 +616,7 @@ def _load_all_v2(dfndir: PathLike) -> Dfns:
608616 return dfns
609617
610618 @staticmethod
611- def load_all (dfndir : PathLike , version : DfnFmtVersion = 1 ) -> Dfns :
619+ def load_all (dfndir : PathLike , version : FormatVersion = 1 ) -> Dfns :
612620 """Load all component definitions from the given directory."""
613621 if version == 1 :
614622 return Dfn ._load_all_v1 (dfndir )
0 commit comments