From c58c7686920f87b1cd10e4b860c8670577fd5a05 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:30:33 +0100 Subject: [PATCH] Fix ruff/pyupgrade issues (UP035) UP035 Import from `collections.abc` instead: `Iterable`, `Iterator`, `Mapping`, `Sequence` UP035 `typing.Dict` is deprecated, use `dict` instead UP035 `typing.List` is deprecated, use `list` instead UP035 `typing.Tuple` is deprecated, use `tuple` instead https://docs.astral.sh/ruff/rules/deprecated-import/ --- zarr/_storage/store.py | 8 ++++++-- zarr/_storage/v3.py | 2 +- zarr/_storage/v3_storage_transformers.py | 3 ++- zarr/creation.py | 3 ++- zarr/meta.py | 3 ++- zarr/n5.py | 2 +- zarr/storage.py | 3 ++- zarr/tests/test_core.py | 3 ++- zarr/tests/test_n5.py | 1 - zarr/tests/util.py | 3 ++- zarr/util.py | 6 +----- 11 files changed, 21 insertions(+), 16 deletions(-) diff --git a/zarr/_storage/store.py b/zarr/_storage/store.py index 5545a8962e..8d239032c1 100644 --- a/zarr/_storage/store.py +++ b/zarr/_storage/store.py @@ -4,7 +4,8 @@ from collections.abc import MutableMapping from copy import copy from string import ascii_letters, digits -from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Union +from typing import Any, Optional, Union +from collections.abc import Mapping, Sequence from zarr.meta import Metadata2, Metadata3 from zarr.util import normalize_storage_path @@ -183,6 +184,9 @@ def rmdir(self, path: str = "") -> None: _rmdir_from_keys(self, path) +_shadowed_list = list + + class StoreV3(BaseStore): _store_version = 3 _metadata_class = Metadata3 @@ -295,7 +299,7 @@ def supports_efficient_get_partial_values(self): def get_partial_values( self, key_ranges: Sequence[tuple[str, tuple[int, Optional[int]]]] - ) -> list[Union[bytes, memoryview, bytearray]]: + ) -> _shadowed_list[Union[bytes, memoryview, bytearray]]: """Get multiple partial values. key_ranges can be an iterable of key, range pairs, where a range specifies two integers range_start and range_length diff --git a/zarr/_storage/v3.py b/zarr/_storage/v3.py index e13e1713db..41241687a1 100644 --- a/zarr/_storage/v3.py +++ b/zarr/_storage/v3.py @@ -3,7 +3,7 @@ from collections import OrderedDict from collections.abc import MutableMapping from threading import Lock -from typing import Union, Dict, Any, Optional +from typing import Union, Any, Optional from zarr.errors import ( MetadataError, diff --git a/zarr/_storage/v3_storage_transformers.py b/zarr/_storage/v3_storage_transformers.py index 10d0815ca0..be3f54c59c 100644 --- a/zarr/_storage/v3_storage_transformers.py +++ b/zarr/_storage/v3_storage_transformers.py @@ -1,7 +1,8 @@ import functools import itertools import os -from typing import NamedTuple, Tuple, Optional, Union, Iterator +from typing import NamedTuple, Optional, Union +from collections.abc import Iterator from numcodecs.compat import ensure_bytes import numpy as np diff --git a/zarr/creation.py b/zarr/creation.py index a5ebb33384..aa3def8adb 100644 --- a/zarr/creation.py +++ b/zarr/creation.py @@ -1,5 +1,6 @@ from collections.abc import MutableMapping -from typing import Optional, Tuple, Union, Sequence +from typing import Optional, Union +from collections.abc import Sequence from warnings import warn import numpy as np diff --git a/zarr/meta.py b/zarr/meta.py index 402e83a14e..275d6d2b03 100644 --- a/zarr/meta.py +++ b/zarr/meta.py @@ -9,7 +9,8 @@ from zarr.errors import MetadataError from zarr.util import json_dumps, json_loads -from typing import cast, Union, Any, List, Mapping as MappingType, Optional, TYPE_CHECKING +from typing import cast, Union, Any, Optional, TYPE_CHECKING +from collections.abc import Mapping as MappingType if TYPE_CHECKING: # pragma: no cover from zarr._storage.store import StorageTransformer diff --git a/zarr/n5.py b/zarr/n5.py index 849274315a..afb669436e 100644 --- a/zarr/n5.py +++ b/zarr/n5.py @@ -4,7 +4,7 @@ import os import struct import sys -from typing import Any, Dict, Optional, cast +from typing import Any, Optional, cast import warnings import numpy as np diff --git a/zarr/storage.py b/zarr/storage.py index c647b2bae6..3df196df51 100644 --- a/zarr/storage.py +++ b/zarr/storage.py @@ -33,7 +33,8 @@ from os import scandir from pickle import PicklingError from threading import Lock, RLock -from typing import Sequence, Mapping, Optional, Union, List, Tuple, Dict, Any +from typing import Optional, Union, Any +from collections.abc import Sequence, Mapping import uuid import time diff --git a/zarr/tests/test_core.py b/zarr/tests/test_core.py index aae4f93bb8..ea16ee6cdc 100644 --- a/zarr/tests/test_core.py +++ b/zarr/tests/test_core.py @@ -3,7 +3,8 @@ import sys import pickle import shutil -from typing import Any, Literal, Optional, Tuple, Union, Sequence +from typing import Any, Literal, Optional, Union +from collections.abc import Sequence import unittest from itertools import zip_longest from tempfile import mkdtemp diff --git a/zarr/tests/test_n5.py b/zarr/tests/test_n5.py index a9de57c971..04f37b69c6 100644 --- a/zarr/tests/test_n5.py +++ b/zarr/tests/test_n5.py @@ -5,7 +5,6 @@ from zarr.storage import atexit_rmtree from numcodecs import GZip import numpy as np -from typing import Tuple import json import atexit diff --git a/zarr/tests/util.py b/zarr/tests/util.py index b3c3249cab..e696ca4b79 100644 --- a/zarr/tests/util.py +++ b/zarr/tests/util.py @@ -1,7 +1,8 @@ import collections import os import tempfile -from typing import Any, Mapping, Sequence +from typing import Any +from collections.abc import Mapping, Sequence from zarr.context import Context from zarr.storage import Store diff --git a/zarr/util.py b/zarr/util.py index e354becf8a..045a409b53 100644 --- a/zarr/util.py +++ b/zarr/util.py @@ -8,16 +8,12 @@ from typing import ( Any, Callable, - Dict, - Iterator, - Mapping, Optional, - Tuple, TypeVar, Union, - Iterable, cast, ) +from collections.abc import Iterator, Mapping, Iterable import numpy as np from asciitree import BoxStyle, LeftAligned