Skip to content

Commit

Permalink
appease codacy: use literal_eval, remove unused vars
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Oct 3, 2024
1 parent 656ff89 commit f850921
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions flopy/mf6/utils/createpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@

import collections
import os
from ast import literal_eval
from collections import UserDict, namedtuple
from dataclasses import asdict, dataclass, replace
from enum import Enum
Expand Down Expand Up @@ -274,7 +275,7 @@ def title(self) -> str:
@property
def base(self) -> str:
"""Base class from which the input context should inherit."""
l, r = self
_, r = self
if self == ("sim", "nam"):
return "MFSimulationBase"
if r is None:
Expand Down Expand Up @@ -378,9 +379,7 @@ def __init__(

def load_dfn(f, name: Optional[DfnName] = None) -> Dfn:
"""
Load an input definition file. Returns a tuple containing
a dictionary of variable specifications as well as a list
of metadata attributes.
Load an input definition from a definition file.
"""

meta = None
Expand All @@ -404,7 +403,7 @@ def load_dfn(f, name: Optional[DfnName] = None) -> Dfn:
tail.pop(1)
meta.append(tail)
continue
head, sep, tail = line.partition("package-type")
_, sep, tail = line.partition("package-type")
if sep == "package-type":
if meta is None:
meta = list
Expand Down Expand Up @@ -808,7 +807,7 @@ def _description(descr: str) -> str:
_, replace, tail = descr.strip().partition("REPLACE")
if replace:
key, _, replacements = tail.strip().partition(" ")
replacements = eval(replacements)
replacements = literal_eval(replacements)
common_var = common.get(key, None)
if common_var is None:
raise ValueError(f"Common variable not found: {key}")
Expand Down Expand Up @@ -1056,7 +1055,7 @@ def _is_implicit_scalar_record():
default = var.get("default", False if type_ is bool else None)
if isinstance(default, str) and type_ is not str:
try:
default = eval(default)
default = literal_eval(default)
except:
pass
if _name in ["continue", "print_input"]: # hack...
Expand Down Expand Up @@ -1616,7 +1615,7 @@ def make_contexts(


_TEMPLATE_ENV = Environment(
loader=PackageLoader("flopy", "mf6/utils/templates/")
loader=PackageLoader("flopy", "mf6/utils/templates/"),
)


Expand Down

0 comments on commit f850921

Please sign in to comment.