Skip to content

Commit

Permalink
codacy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Oct 28, 2024
1 parent 530e100 commit 6d57fae
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions flopy/mf6/utils/codegen/dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def parse(cls, v: str) -> "Dfn.Name":

def __init__(
self,
vars: Optional[Vars] = None,
data: Optional[Vars] = None,
name: Optional[Name] = None,
meta: Optional[Dict[str, Any]] = None,
):
self.data = OMD(vars)
self.data = OMD(data)
self.name = name
self.meta = meta

Expand All @@ -107,7 +107,7 @@ def _load(f, common: Optional[dict] = None) -> Tuple[OMD, List[str]]:
"""
var = dict()
vars = list()
flat = list()
meta = list()
common = common or dict()

Expand Down Expand Up @@ -140,7 +140,7 @@ def _load(f, common: Optional[dict] = None) -> Tuple[OMD, List[str]]:
# block of attributes
if not any(line):
if any(var):
vars.append((var["name"], var))
flat.append((var["name"], var))
var = dict()
continue

Expand Down Expand Up @@ -176,9 +176,9 @@ def _load(f, common: Optional[dict] = None) -> Tuple[OMD, List[str]]:

# add the final parameter
if any(var):
vars.append((var["name"], var))
flat.append((var["name"], var))

return OMD(vars), meta
return OMD(flat), meta

@classmethod
def load(
Expand All @@ -192,7 +192,7 @@ def load(

refs = refs or dict()
referenced = dict()
vars, meta = Dfn._load(f, **kwargs)
flat, meta = Dfn._load(f, **kwargs)

def _map(spec: Dict[str, Any]) -> Var:
"""
Expand Down Expand Up @@ -236,12 +236,12 @@ def _map(spec: Dict[str, Any]) -> Var:

def _fields(record_name: str) -> Vars:
"""Recursively load/convert a record's fields."""
record = next(iter(vars.getlist(record_name)), None)
record = next(iter(flat.getlist(record_name)), None)
assert record
names = _type.split()[1:]
fields = {
v["name"]: _map(v)
for v in vars.values(multi=True)
for v in flat.values(multi=True)
if v["name"] in names
and not v["type"].startswith("record")
and v.get("in_record", False)
Expand Down Expand Up @@ -290,7 +290,7 @@ def _fields(record_name: str) -> Vars:
# fields directly inside the recarray (implicit). list
# data for unions/keystrings necessarily comes nested.

is_explicit_record = n_names == 1 and vars[names[0]][
is_explicit_record = n_names == 1 and flat[names[0]][
"type"
].startswith("record")

Expand All @@ -299,13 +299,13 @@ def _is_implicit_scalar_record():
# only scalar fields
types = [
v["type"]
for v in vars.values(multi=True)
for v in flat.values(multi=True)
if v["name"] in names and v.get("in_record", False)
]
return all(t in _SCALARS for t in types)

if is_explicit_record:
record = next(iter(vars.getlist(names[0])), None)
record = next(iter(flat.getlist(names[0])), None)
children = {names[0]: _map(record)}
kind = Var.Kind.List
elif _is_implicit_scalar_record():
Expand All @@ -327,7 +327,7 @@ def _is_implicit_scalar_record():
# implicit complex record (i.e. some fields are records or unions)
fields = {
v["name"]: _map(v)
for v in vars.values(multi=True)
for v in flat.values(multi=True)
if v["name"] in names and v.get("in_record", False)
}
first = list(fields.values())[0]
Expand All @@ -353,7 +353,7 @@ def _is_implicit_scalar_record():
names = _type.split()[1:]
children = {
v["name"]: _map(v)
for v in vars.values(multi=True)
for v in flat.values(multi=True)
if v["name"] in names and v.get("in_record", False)
}
kind = Var.Kind.Union
Expand Down Expand Up @@ -402,24 +402,24 @@ def _is_implicit_scalar_record():

# pass the original DFN representation as
# metadata so the shim can use it for now
_vars = list(vars.values(multi=True))
_vars = list(flat.values(multi=True))

# convert input variable specs to
# structured form, descending into
# composites recursively as needed
vars = {
flat = {
var["name"]: _map(var)
for var in vars.values(multi=True)
for var in flat.values(multi=True)
if not var.get("in_record", False)
}

# reset the var name. we may have altered
# it when converting the variable e.g. to
# avoid collision with a reserved keyword
vars = {v.name: v for v in vars.values()}
flat = {v.name: v for v in flat.values()}

return cls(
vars,
flat,
name,
{
"dfn": (_vars, meta),
Expand Down

0 comments on commit 6d57fae

Please sign in to comment.