Skip to content

Commit 9cbb49f

Browse files
authored
Merge pull request #989 from xcube-dev/konstntokas-xxx-apply_pyupgrade
Used pyupgrade to automatically upgrade syntax for newer versions of the language
2 parents 2913f67 + 8da847f commit 9cbb49f

File tree

202 files changed

+1117
-1030
lines changed

Some content is hidden

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

202 files changed

+1117
-1030
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@
9090
* Added project URLs and classifiers to `setup.py`, which will be shown in the
9191
left sidebar on the [PyPI xcube-core](https://pypi.org/project/xcube-core/) webpage.
9292

93+
* Used [`pyupgrade`](https://github.com/asottile/pyupgrade) to automatically upgrade
94+
language syntax for Python versions >= 3.9.
95+
9396
## Changes in 1.5.1
9497

9598
* Embedded [xcube-viewer 1.1.1](https://github.com/xcube-dev/xcube-viewer/releases/tag/v1.1.1).

test/cli/helpers.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818

1919

2020
class CliTest(unittest.TestCase, metaclass=ABCMeta):
21-
def invoke_cli(self, args: List[str]):
21+
def invoke_cli(self, args: list[str]):
2222
self.runner = click.testing.CliRunner(mix_stderr=False)
2323
# noinspection PyTypeChecker
2424
return self.runner.invoke(cli, args, catch_exceptions=False)
2525

2626

2727
class CliDataTest(CliTest, metaclass=ABCMeta):
28-
def outputs(self) -> List[str]:
28+
def outputs(self) -> list[str]:
2929
return []
3030

3131
def time_periods(self) -> int:
3232
return 5
3333

34-
def chunks(self) -> Optional[Dict[str, int]]:
34+
def chunks(self) -> Optional[dict[str, int]]:
3535
return None
3636

3737
def setUp(self):

test/cli/test_compute.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
class ComputeCliTest(CliDataTest):
16-
def outputs(self) -> List[str]:
16+
def outputs(self) -> list[str]:
1717
return [OUTPUT_PATH]
1818

1919
def test_help_option(self):

test/cli/test_genpts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class GenptsCliTest(CliDataTest):
19-
def outputs(self) -> List[str]:
19+
def outputs(self) -> list[str]:
2020
return [TEST_CSV, TEST_GEOJSON]
2121

2222
def test_help_option(self):

test/cli/test_grid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_find_close_resolutions(self):
9696

9797
class GridCliTest(unittest.TestCase):
9898
@classmethod
99-
def invoke_cli(cls, args: List[str]):
99+
def invoke_cli(cls, args: list[str]):
100100
runner = click.testing.CliRunner()
101101
return runner.invoke(cli, args)
102102

test/cli/test_level.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ def test_help_option(self):
2121
class LevelDataTest(CliDataTest):
2222
TEST_OUTPUT = "test.levels"
2323

24-
def outputs(self) -> List[str]:
24+
def outputs(self) -> list[str]:
2525
return [LevelDataTest.TEST_OUTPUT, "my.levels"]
2626

27-
def chunks(self) -> Optional[Dict[str, int]]:
27+
def chunks(self) -> Optional[dict[str, int]]:
2828
return dict(time=1, lat=90, lon=180)
2929

3030
def test_all_defaults(self):
@@ -64,7 +64,7 @@ def test_with_tile_size_and_num_levels(self):
6464
)
6565

6666
def _assert_result_ok(
67-
self, result, level_chunks: List[Tuple], output_path: str, message_regex: str
67+
self, result, level_chunks: list[tuple], output_path: str, message_regex: str
6868
):
6969
self.assertEqual(0, result.exit_code)
7070
self.assertRegex(result.stderr, message_regex)

test/cli/test_rectify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class RectifyTest(CliDataTest):
13-
def outputs(self) -> List[str]:
13+
def outputs(self) -> list[str]:
1414
return ["out.zarr"]
1515

1616
def test_rectify_without_vars(self):

test/cli/test_resample.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def test_help_option(self):
1818

1919

2020
class ResampleDataTest(CliDataTest):
21-
def outputs(self) -> List[str]:
21+
def outputs(self) -> list[str]:
2222
return ["out.zarr", "resampled.zarr"]
2323

2424
def test_all_defaults(self):

test/core/byoa/test_data/user_code/impl/algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
def compute_chunk(
12-
input_var_1: np.ndarray, input_var_2: np.ndarray, input_params: Dict[str, Any]
12+
input_var_1: np.ndarray, input_var_2: np.ndarray, input_params: dict[str, Any]
1313
) -> xr.Dataset:
1414
factor_1: float = input_params["factor_1"]
1515
factor_2: float = input_params["factor_2"]

test/core/diagnosticstore.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import time
66
from collections.abc import MutableMapping
77
from types import MethodType
8-
from typing import TypeVar, Iterator, List, Callable, Any, Tuple
8+
from typing import TypeVar, List, Callable, Any, Tuple
9+
from collections.abc import Iterator
910

1011
_KT = TypeVar("_KT")
1112
_VT = TypeVar("_VT")
@@ -17,7 +18,7 @@ class DiagnosticStore(MutableMapping):
1718
def __init__(
1819
self,
1920
delegate: MutableMapping,
20-
observer: Callable[[int, float, str, List[Tuple[str, Any]]], None] = None,
21+
observer: Callable[[int, float, str, list[tuple[str, Any]]], None] = None,
2122
):
2223
self._delegate = delegate
2324
self._observer = observer or logging_observer()
@@ -26,10 +27,10 @@ def __init__(
2627
self._add_optional_method("rmdir", ["path"])
2728
self._add_optional_method("rename", ["from_path", "to_path"])
2829

29-
def _add_optional_method(self, method_name: str, arg_names: List[str]):
30+
def _add_optional_method(self, method_name: str, arg_names: list[str]):
3031
if hasattr(self._delegate, method_name):
3132

32-
def method(_self, *args) -> List[str]:
33+
def method(_self, *args) -> list[str]:
3334
return _self.call_and_notify(
3435
method_name, *[(arg_names[i], args[i]) for i in range(len(args))]
3536
)

test/core/gen/test_gen.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
import os
66
import unittest
7-
from typing import Any, Dict, Optional, Sequence, Tuple
7+
from typing import Any, Dict, Optional, Tuple
8+
from collections.abc import Sequence
89

910
import numpy as np
1011
import xarray as xr
@@ -731,7 +732,7 @@ def assert_cube_ok(
731732
self,
732733
cube: xr.Dataset,
733734
expected_time_dim: int,
734-
expected_extra_attrs: Dict[str, Any],
735+
expected_extra_attrs: dict[str, Any],
735736
expected_output_vars: Sequence[str] = ("analysed_sst",),
736737
):
737738
self.assertEqual(
@@ -813,7 +814,7 @@ def gen_cube_wrapper(
813814
input_processor_name=None,
814815
processed_variables=None,
815816
output_variables=(("analysed_sst", None),),
816-
) -> Tuple[bool, Optional[str]]:
817+
) -> tuple[bool, Optional[str]]:
817818
output = None
818819

819820
def output_monitor(msg):

test/core/gen2/local/test_generator.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
class LocalCubeGeneratorTest(unittest.TestCase):
29-
REQUEST: Dict[str, Any] = dict(
29+
REQUEST: dict[str, Any] = dict(
3030
input_config=dict(store_id="memory", data_id="S2L2A.zarr"),
3131
cube_config=dict(
3232
variable_names=["B01", "B02", "B03"],

test/core/gen2/remote/server.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
from xcube.util.temp import new_temp_dir
3131
from xcube.util.temp import new_temp_file
3232

33-
Job = Tuple[
33+
Job = tuple[
3434
subprocess.Popen, # process
3535
str, # result_path
3636
str, # start_time
37-
Dict[str, Any], # updated state object
37+
dict[str, Any], # updated state object
3838
]
3939

4040
STORES_CONFIG_PATH: str = ""
41-
JOBS: Dict[str, Job] = {}
41+
JOBS: dict[str, Job] = {}
4242

4343
app = flask.Flask("test.core.gen2.remote.server")
4444

@@ -147,7 +147,7 @@ def _get_generate_cube_result(
147147
process: Optional[subprocess.Popen],
148148
result_path: Optional[str],
149149
job_id: Optional[str],
150-
) -> Tuple[Dict[str, Any], int]:
150+
) -> tuple[dict[str, Any], int]:
151151
global JOBS
152152

153153
if process is not None:
@@ -203,7 +203,7 @@ def _get_generate_cube_result(
203203

204204

205205
def _get_set_status_code(
206-
result_json: Dict[str, Any], success_code: int = 200, failure_code: int = 400
206+
result_json: dict[str, Any], success_code: int = 200, failure_code: int = 400
207207
) -> int:
208208
status_code = result_json.get("status_code")
209209
if status_code is None:

test/core/gen2/remote/test_generator.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def make_result(
2222
worked,
2323
total_work,
2424
failed=False,
25-
output: List[str] = None,
26-
job_result: Dict[str, Any] = None,
25+
output: list[str] = None,
26+
job_result: dict[str, Any] = None,
2727
):
2828
json = {
2929
"job_id": "93",

test/core/gridmapping/test_cfconv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def test_cf_2d_data_vars(self):
231231
self.assertVarNames({"noise", "crs", "lon", "lat"}, set(), decode_cf=False)
232232

233233
def assertVarNames(
234-
self, exp_data_vars: Set[str], exp_coords: Set[str], decode_cf: bool
234+
self, exp_data_vars: set[str], exp_coords: set[str], decode_cf: bool
235235
):
236236
ds1 = xr.open_zarr("noise.zarr", decode_cf=decode_cf)
237237
self.assertEqual(exp_coords, set(ds1.coords))

test/core/mldataset/test_fs.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import math
77
import unittest
8-
from typing import Optional, List, Mapping
8+
from typing import Optional, List
9+
from collections.abc import Mapping
910

1011
import fsspec
1112
import fsspec.core
@@ -85,10 +86,10 @@ def assert_io_ok(
8586
tile_size: Optional[int],
8687
use_saved_levels: bool,
8788
base_dataset_path: Optional[str],
88-
expected_files: List[str],
89+
expected_files: list[str],
8990
expected_num_levels: int,
9091
expected_agg_methods: Optional[Mapping[str, AggMethod]],
91-
expected_tile_size: List[int],
92+
expected_tile_size: list[int],
9293
):
9394
fs = self.fs
9495
FsMultiLevelDataset.write_dataset(
@@ -105,7 +106,7 @@ def assert_io_ok(
105106
)
106107
self.assertTrue(fs.isdir(path))
107108
self.assertEqual(
108-
set([f"/{path}/{f}" for f in expected_files]),
109+
{f"/{path}/{f}" for f in expected_files},
109110
set(fs.listdir(path, detail=False)),
110111
)
111112

test/core/resampling/test_rectify.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def test_rectify_2x2_to_13x13_none(self):
733733

734734
def _assert_shape_and_dim(
735735
self, target_ds, size, chunks=None, var_names=("rad",)
736-
) -> Tuple[xr.DataArray, ...]:
736+
) -> tuple[xr.DataArray, ...]:
737737
w, h = size
738738

739739
self.assertIn("lon", target_ds)

test/core/store/fs/test_plugin.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class FsDataStoreAndAccessorsPluginTest(unittest.TestCase):
4646
def test_find_data_store_extensions(self):
4747
extensions = find_data_store_extensions()
4848
self.assertTrue(len(extensions) >= len(expected_fs_store_ids))
49-
self.assertEqual({"xcube.core.store"}, set(ext.point for ext in extensions))
49+
self.assertEqual({"xcube.core.store"}, {ext.point for ext in extensions})
5050
self.assertTrue(
51-
expected_fs_store_ids.issubset(set(ext.name for ext in extensions))
51+
expected_fs_store_ids.issubset({ext.name for ext in extensions})
5252
)
5353
for ext in extensions:
5454
if ext.name not in expected_fs_store_ids:
@@ -70,10 +70,10 @@ def test_find_data_opener_extensions(self):
7070
extensions = find_data_opener_extensions()
7171
self.assertTrue(len(extensions) >= len(expected_fs_data_accessor_ids))
7272
self.assertEqual(
73-
{"xcube.core.store.opener"}, set(ext.point for ext in extensions)
73+
{"xcube.core.store.opener"}, {ext.point for ext in extensions}
7474
)
7575
self.assertTrue(
76-
expected_fs_data_accessor_ids.issubset(set(ext.name for ext in extensions))
76+
expected_fs_data_accessor_ids.issubset({ext.name for ext in extensions})
7777
)
7878
for ext in extensions:
7979
if ext.name not in expected_fs_data_accessor_ids:
@@ -89,10 +89,10 @@ def test_find_data_writer_extensions(self):
8989
extensions = find_data_writer_extensions()
9090
self.assertTrue(len(extensions) >= len(expected_fs_data_accessor_ids))
9191
self.assertEqual(
92-
{"xcube.core.store.writer"}, set(ext.point for ext in extensions)
92+
{"xcube.core.store.writer"}, {ext.point for ext in extensions}
9393
)
9494
self.assertTrue(
95-
expected_fs_data_accessor_ids.issubset(set(ext.name for ext in extensions))
95+
expected_fs_data_accessor_ids.issubset({ext.name for ext in extensions})
9696
)
9797
for ext in extensions:
9898
if ext.name not in expected_fs_data_accessor_ids:

test/core/store/fs/test_registry.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,13 @@ def _assert_dataset_supported(
325325
data_store: FsDataStore,
326326
filename_ext: str,
327327
requested_dtype_alias: Optional[str],
328-
expected_dtype_aliases: Set[str],
329-
expected_return_type: Union[Type[xr.Dataset], Type[MultiLevelDataset]],
328+
expected_dtype_aliases: set[str],
329+
expected_return_type: Union[type[xr.Dataset], type[MultiLevelDataset]],
330330
expected_descriptor_type: Optional[
331-
Union[Type[DatasetDescriptor], Type[MultiLevelDatasetDescriptor]]
331+
Union[type[DatasetDescriptor], type[MultiLevelDatasetDescriptor]]
332332
] = None,
333-
write_params: Optional[Dict[str, Any]] = None,
334-
open_params: Optional[Dict[str, Any]] = None,
333+
write_params: Optional[dict[str, Any]] = None,
334+
open_params: Optional[dict[str, Any]] = None,
335335
assert_data_ok: Optional[Callable[[Any], Any]] = None,
336336
):
337337
"""Call all DataStore operations to ensure data of type

test/core/store/fs/test_subset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CommonTest(unittest.TestCase, ABC):
2525

2626
@classmethod
2727
@abstractmethod
28-
def get_fs_root(cls) -> Tuple[fsspec.AbstractFileSystem, str]:
28+
def get_fs_root(cls) -> tuple[fsspec.AbstractFileSystem, str]:
2929
pass
3030

3131
@classmethod
@@ -151,7 +151,7 @@ def test_include_exclude(self):
151151

152152
class MemoryFsStoreSubsetTest(FsStoreSubset.CommonTest):
153153
@classmethod
154-
def get_fs_root(cls) -> Tuple[fsspec.AbstractFileSystem, str]:
154+
def get_fs_root(cls) -> tuple[fsspec.AbstractFileSystem, str]:
155155
fs = fsspec.get_filesystem_class("memory")()
156156
root = "xcube"
157157
fs.mkdirs(root, exist_ok=True)
@@ -166,7 +166,7 @@ def new_store(cls, **params) -> FsDataStore:
166166

167167
class FileFsStoreSubsetTest(FsStoreSubset.CommonTest):
168168
@classmethod
169-
def get_fs_root(cls) -> Tuple[fsspec.AbstractFileSystem, str]:
169+
def get_fs_root(cls) -> tuple[fsspec.AbstractFileSystem, str]:
170170
return fsspec.get_filesystem_class("file")(), new_temp_dir()
171171

172172
@classmethod
@@ -180,7 +180,7 @@ def new_store(cls, **params) -> FsDataStore:
180180
@unittest.skip("OSError: [Errno 5] Internal Server Error")
181181
class S3FsStoreSubsetTest(FsStoreSubset.CommonTest, S3Test):
182182
@classmethod
183-
def get_fs_root(cls) -> Tuple[fsspec.AbstractFileSystem, str]:
183+
def get_fs_root(cls) -> tuple[fsspec.AbstractFileSystem, str]:
184184
fs = fsspec.get_filesystem_class("s3")(**cls.get_storage_options())
185185
root = "xcube"
186186
fs.mkdirs(root, exist_ok=True)

test/core/store/ref/test_store.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def create_ref_paths():
5656
return [cube_ref_path] + reference_file_paths
5757

5858

59-
def delete_ref_paths(ref_paths: List[str]):
59+
def delete_ref_paths(ref_paths: list[str]):
6060
fs = fsspec.filesystem("file")
6161
for ref_path in ref_paths:
6262
fs.delete(ref_path)
6363

6464

6565
# noinspection PyPep8Naming,PyUnresolvedReferences
6666
class KerchunkMixin:
67-
ref_paths: List[str] = []
67+
ref_paths: list[str] = []
6868

6969
@classmethod
7070
def setUpClass(cls):

test/core/store/test_descriptor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_new_ml_dataset_descriptor(self):
5858
def assertExpectedDescriptor(
5959
self,
6060
descriptor: DataDescriptor,
61-
expected_type: Type[DataDescriptor],
61+
expected_type: type[DataDescriptor],
6262
expected_data_type_alias: str,
6363
):
6464
self.assertIsInstance(descriptor, DatasetDescriptor)

0 commit comments

Comments
 (0)