Skip to content

Commit c2b57cc

Browse files
Remove unnecessary Python < 3.10 __future__ and typing imports (#312)
1 parent b46a0a9 commit c2b57cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+124
-219
lines changed

e3sm_to_cmip/argparser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import sys
3-
from typing import List
43

54
from e3sm_to_cmip import __version__
65
from e3sm_to_cmip.util import FREQUENCIES
@@ -239,12 +238,12 @@ def setup_argparser() -> argparse.ArgumentParser:
239238
return parser
240239

241240

242-
def parse_args(args: List[str] | None) -> argparse.Namespace:
241+
def parse_args(args: list[str] | None) -> argparse.Namespace:
243242
"""Parses command line arguments.
244243
245244
Parameters
246245
----------
247-
args : List[str] | None
246+
args : list[str] | None
248247
A list of arguments, useful for debugging purposes to simulate a
249248
passing arguments via the CLI.
250249

e3sm_to_cmip/cmor_handlers/handler.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import logging
33
import os
4-
from typing import Any, Dict, KeysView, List, Literal, Optional, Tuple, TypedDict
4+
from typing import Any, KeysView, Literal, TypedDict
55

66
import cmor
77
import numpy as np
@@ -32,7 +32,7 @@ def __init__(
3232
self,
3333
name: str,
3434
units: str,
35-
raw_variables: List[str],
35+
raw_variables: list[str],
3636
table: str,
3737
):
3838
# The CMIP variable name.
@@ -79,11 +79,11 @@ def __init__(
7979
name: str,
8080
units: str,
8181
table: str,
82-
raw_variables: List[str],
83-
unit_conversion: Optional[str] = None,
84-
formula: Optional[str] = None,
85-
positive: Optional[Literal["up", "down"]] = None,
86-
levels: Optional[Levels] = None,
82+
raw_variables: list[str],
83+
unit_conversion: str | None = None,
84+
formula: str | None = None,
85+
positive: Literal["up", "down"] | None = None,
86+
levels: Levels | None = None,
8787
):
8888
super().__init__(name, units, raw_variables, table)
8989

@@ -135,7 +135,7 @@ def __init__(
135135
self.levels = levels
136136

137137
# Output data for CMORizing.
138-
self.output_data: Optional[np.ndarray] = None
138+
self.output_data: np.ndarray | None = None
139139

140140
def __eq__(self, other):
141141
if isinstance(self, other.__class__):
@@ -155,7 +155,7 @@ def __eq__(self, other):
155155
def __str__(self):
156156
return yaml.dump(self.__dict__, default_flow_style=False, sort_keys=False)
157157

158-
def to_dict(self) -> Dict[str, Any]:
158+
def to_dict(self) -> dict[str, Any]:
159159
"""
160160
Return __dict__ with additional entries to support existing e3sm_to_cmip
161161
functions.
@@ -166,7 +166,7 @@ def to_dict(self) -> Dict[str, Any]:
166166
167167
Returns
168168
-------
169-
Dict[str, Any]
169+
dict[str, Any]
170170
__dict__ with additional entries.
171171
"""
172172
# TODO: Remove this method e3sm_to_cmip functions parse VarHandler
@@ -175,7 +175,7 @@ def to_dict(self) -> Dict[str, Any]:
175175

176176
def cmorize(
177177
self,
178-
vars_to_filepaths: Dict[str, List[str]],
178+
vars_to_filepaths: dict[str, list[str]],
179179
tables_path: str,
180180
metadata_path: str,
181181
cmor_log_dir: str,
@@ -185,7 +185,7 @@ def cmorize(
185185
186186
Parameters
187187
----------
188-
vars_to_filepaths : Dict[str, List[str]]
188+
vars_to_filepaths : dict[str, list[str]]
189189
A dictionary mapping E3SM raw variables to a list of filepath(s).
190190
tables_path : str
191191
The path to directory containing CMOR Tables directory.
@@ -272,13 +272,13 @@ def cmorize(
272272
return is_cmor_successful
273273

274274
def _all_vars_have_filepaths(
275-
self, vars_to_filespaths: Dict[str, List[str]]
275+
self, vars_to_filespaths: dict[str, list[str]]
276276
) -> bool:
277277
"""Checks if all raw variables have filepaths found.
278278
279279
Parameters
280280
----------
281-
vars_to_filespaths : Dict[str, List[str]]
281+
vars_to_filespaths : dict[str, list[str]]
282282
A dictionary of raw variables to filepaths.
283283
284284
Returns
@@ -347,13 +347,13 @@ def _get_var_time_dim(self, table_path: str) -> str | None:
347347
return None
348348

349349
def _get_mfdataset(
350-
self, vars_to_filepaths: Dict[str, List[str]], index: int, time_dim: str | None
350+
self, vars_to_filepaths: dict[str, list[str]], index: int, time_dim: str | None
351351
) -> xr.Dataset:
352352
"""Get the xr.Dataset using the filepaths for all raw variables.
353353
354354
Parameters
355355
----------
356-
vars_to_filepaths : Dict[str, List[str]]
356+
vars_to_filepaths : dict[str, list[str]]
357357
A dictionary mapping E3SM raw variables to a list of filepath(s).
358358
index : int
359359
The index representing the time range for the file.
@@ -374,7 +374,7 @@ def _get_mfdataset(
374374
"""
375375
# Sort the input filepath names for each variable to ensure time axis data
376376
# is aligned and in order across variables.
377-
sorted_v_to_fp: Dict[str, List[str]] = {
377+
sorted_v_to_fp: dict[str, list[str]] = {
378378
var: sorted(vars_to_filepaths[var]) for var in vars_to_filepaths
379379
}
380380

@@ -442,7 +442,7 @@ def _get_time_bnds_key(self, data_vars: KeysView[Any]) -> str:
442442

443443
def _get_cmor_axis_ids_and_ips_id(
444444
self, ds: xr.Dataset, time_dim: str | None
445-
) -> Tuple[Dict[str, int], int | None]:
445+
) -> tuple[dict[str, int], int | None]:
446446
"""Create the CMOR axes objects, which are set globally in the CMOR module.
447447
448448
The CMOR ids for "time" and "lev" should be the starting elements of the
@@ -462,7 +462,7 @@ def _get_cmor_axis_ids_and_ips_id(
462462
463463
Returns
464464
-------
465-
Tuple[Dict[str, int], int | None]
465+
tuple[dict[str, int], int | None]
466466
A tuple with the first element being a dictionary (value is the
467467
CMOR axis and key is the ID of the CMOR axis), and the second
468468
element being the CMOR zfactor ID for ips if the dataset and handler
@@ -471,7 +471,7 @@ def _get_cmor_axis_ids_and_ips_id(
471471
Example:
472472
({"time": 0, "lev": 1, "lat": 2, "lon": 3}, 4)
473473
"""
474-
axis_id_map: Dict[str, int] = {}
474+
axis_id_map: dict[str, int] = {}
475475
cmor_ips_id = None
476476

477477
if time_dim is not None:
@@ -540,7 +540,7 @@ def _has_hybrid_sigma_levels(self, ds: xr.Dataset):
540540
return set(hybrid_sigma_levels).issubset(ds.data_vars)
541541

542542
def _set_cmor_zfactor_for_hybrid_levels(
543-
self, ds: xr.Dataset, cmor_axis_id_map: Dict[str, cmor.axis]
543+
self, ds: xr.Dataset, cmor_axis_id_map: dict[str, cmor.axis]
544544
):
545545
lev_id = cmor_axis_id_map["lev"]
546546
lev_name = self.levels["name"] # type: ignore
@@ -580,13 +580,13 @@ def _set_cmor_zfactor_for_hybrid_levels(
580580
)
581581

582582
def _set_and_get_cmor_zfactor_ips_id(
583-
self, cmor_axis_id_map: Dict[str, cmor.axis]
583+
self, cmor_axis_id_map: dict[str, cmor.axis]
584584
) -> int:
585585
"""Creates ips as a cmor.zfactor and returns its global CMOR id.
586586
587587
Parameters
588588
----------
589-
cmor_axis_id_map : Dict[str, cmor.axis]
589+
cmor_axis_id_map : dict[str, cmor.axis]
590590
A dictionary mapping the name of a CMOR axis set globally to its CMOR axis
591591
ID.
592592

e3sm_to_cmip/cmor_handlers/mpas_vars/fsitherm.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Water Flux into Sea Water due to Sea Ice Thermodynamics, fsitherm
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/hfds.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Downward Heat Flux at Sea Water Surface, hfds
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/hfsifrazil.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Heat Flux into Sea Water due to Frazil Ice Formation, hfsifrazil
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/masscello.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Ocean Grid-Cell Mass per area, masscello
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import netCDF4
86
import xarray
97

e3sm_to_cmip/cmor_handlers/mpas_vars/masso.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Sea Water Mass, masso
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/mlotst.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Ocean Mixed Layer Thickness Defined by Sigma T, mlotst
33
"""
44

5-
from __future__ import absolute_import
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/msftmz.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Ocean Meridional Overturning Mass Streamfunction, msftmz
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

e3sm_to_cmip/cmor_handlers/mpas_vars/pbo.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
compute Sea Water Pressure at Sea floor, pbo
33
"""
44

5-
from __future__ import absolute_import, division, print_function
6-
75
import xarray
86

97
from e3sm_to_cmip import mpas, util

0 commit comments

Comments
 (0)