Skip to content

Commit

Permalink
Replace parser.readfp() with parser.read_file() for Python 3.12 s…
Browse files Browse the repository at this point in the history
…upport (#765)
  • Loading branch information
tomvothecoder authored Dec 12, 2023
1 parent 633b52c commit 7e43612
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions e3sm_diags/parser/core_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,21 +815,21 @@ def _get_cfg_parameters(
parameters = []

cfg_file_obj = self._create_cfg_hash_titles(cfg_file)
kwargs = (
{"strict": False} if sys.version_info[0] >= 3 else {}
) # 'strict' keyword doesn't work in Python 2.
config = configparser.ConfigParser( # type: ignore
**kwargs
) # Allow for two lines to be the same.
config.readfp(cfg_file_obj)

for section in config.sections():

# Setting `strict=False` enables the parser to allow for any section
# or duplicates while reading from a single source. This is required
# because .cfg diagnostic files might contain duplicate sections with
# slight tweaks based on the set.
parser = configparser.ConfigParser(strict=False)
parser.read_file(cfg_file_obj)

for section in parser.sections():
p = self._parameter_cls()

# Remove all of the variables.
p.__dict__.clear()

for k, v in config.items(section):
for k, v in parser.items(section):
v = yaml.safe_load(v)
setattr(p, k, v)

Expand Down

0 comments on commit 7e43612

Please sign in to comment.