Skip to content

Commit 27834ff

Browse files
authored
feat(dfn): add get_fields function (#230)
Get a flat dict of top-level fields. Convenient when you don't need to care about block structure.
1 parent 2e4060c commit 27834ff

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

modflow_devtools/dfn.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ def get_blocks(dfn: "Dfn") -> Blocks:
137137
)
138138

139139

140+
def get_fields(dfn: "Dfn") -> Fields:
141+
"""
142+
Extract a flat dictionary of fields from an input definition.
143+
Only top-level fields are included, i.e. subfields of records
144+
or recarrays are not included.
145+
"""
146+
fields = {}
147+
for block in get_blocks(dfn).values():
148+
for field in block.values():
149+
if field["name"] in fields:
150+
warn(f"Duplicate field name {field['name']} in {dfn['name']}")
151+
fields[field["name"]] = field
152+
return fields
153+
154+
140155
class Field(TypedDict):
141156
"""A field specification."""
142157

0 commit comments

Comments
 (0)