Skip to content

Commit

Permalink
Fix deepsource.io issues (#1080)
Browse files Browse the repository at this point in the history
* Use a ternary if/else instead of and/or

An instance of the pre-Python 2.5 ternary syntax is being used.
Using [condition] and [on_true] or [on_false] may give wrong
results when on_true has a false boolean value.

* Remove unneeded `not`

* Use `is` when comparing `type` of two objects

* Unnecessary use of a comprehension

* Unnecessary `None` provided as default

Unlike pop() which raises a KeyError by default, get() returns None by default.

Co-authored-by: Josh Moore <j.a.moore@dundee.ac.uk>
  • Loading branch information
DimitriPapadopoulos and joshmoore committed Jul 19, 2022
1 parent 4b83302 commit ece1810
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
4 changes: 3 additions & 1 deletion docs/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ Documentation
Maintenance
~~~~~~~~~~~

* Fix a few DeepSource.io alerts
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>` :issue:`1080`.

* Fix spelling.
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>`, :issue:`1073`.


.. _release_2.12.0:

2.12.0
Expand Down
2 changes: 1 addition & 1 deletion zarr/convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
"""

# normalize parameters
zarr_version = kwargs.get('zarr_version', None)
zarr_version = kwargs.get('zarr_version')
store = normalize_store_arg(store, storage_options=kwargs.get("storage_options"), mode=mode,
zarr_version=zarr_version)
if mode not in {'r', 'r+'}:
Expand Down
2 changes: 1 addition & 1 deletion zarr/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=N
storage_options=storage_options,
mode=mode,
zarr_version=zarr_version)
if not getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION) == zarr_version:
if getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION) != zarr_version:
raise ValueError(
"zarr_version of store and chunk_store must match"
)
Expand Down
2 changes: 1 addition & 1 deletion zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ def __contains__(self, key):
return key in self.map

def __eq__(self, other):
return (type(self) == type(other) and self.map == other.map
return (type(self) is type(other) and self.map == other.map
and self.mode == other.mode)

def keys(self):
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_convenience.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)
from zarr.tests.util import have_fsspec

_VERSIONS = v3_api_available and (2, 3) or (2,)
_VERSIONS = ((2, 3) if v3_api_available else (2, ))


def _init_creation_kwargs(zarr_version):
Expand Down
12 changes: 6 additions & 6 deletions zarr/tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
from zarr.sync import ThreadSynchronizer

_VERSIONS = v3_api_available and (None, 2, 3) or (None, 2)
_VERSIONS2 = v3_api_available and (2, 3) or (2,)
_VERSIONS = ((None, 2, 3) if v3_api_available else (None, 2))
_VERSIONS2 = ((2, 3) if v3_api_available else (2, ))


# something bcolz-like
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_empty_like(zarr_version):
z = empty(100, chunks=10, dtype='f4', compressor=Zlib(5),
order='F', **kwargs)
# zarr_version will be inferred from z, but have to specify a path in v3
z2 = empty_like(z, path=kwargs.get('path', None))
z2 = empty_like(z, path=kwargs.get('path'))
assert z.shape == z2.shape
assert z.chunks == z2.chunks
assert z.dtype == z2.dtype
Expand Down Expand Up @@ -479,7 +479,7 @@ def test_zeros_like(zarr_version):
# zarr array
z = zeros(100, chunks=10, dtype='f4', compressor=Zlib(5),
order='F', **kwargs)
z2 = zeros_like(z, path=kwargs.get('path', None))
z2 = zeros_like(z, path=kwargs.get('path'))
assert z.shape == z2.shape
assert z.chunks == z2.chunks
assert z.dtype == z2.dtype
Expand All @@ -506,7 +506,7 @@ def test_ones_like(zarr_version):
# zarr array
z = ones(100, chunks=10, dtype='f4', compressor=Zlib(5),
order='F', **kwargs)
z2 = ones_like(z, path=kwargs.get('path', None))
z2 = ones_like(z, path=kwargs.get('path'))
assert z.shape == z2.shape
assert z.chunks == z2.chunks
assert z.dtype == z2.dtype
Expand All @@ -533,7 +533,7 @@ def test_full_like(zarr_version):

z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
fill_value=42, order='F', **kwargs)
z2 = full_like(z, path=kwargs.get('path', None))
z2 = full_like(z, path=kwargs.get('path'))
assert z.shape == z2.shape
assert z.chunks == z2.chunks
assert z.dtype == z2.dtype
Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from zarr.tests.util import skip_test_env_var, have_fsspec, abs_container


_VERSIONS = v3_api_available and (2, 3) or (2,)
_VERSIONS = ((2, 3) if v3_api_available else (2, ))

# noinspection PyStatementEffect

Expand Down
2 changes: 1 addition & 1 deletion zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,7 @@ def test_iterators_with_prefix(self):
assert 4 == len(store)
keys = [prefix + 'a', prefix + 'b', prefix + 'c/d', prefix + 'c/e/f']
values = [b'aaa', b'bbb', b'ddd', b'fff']
items = [(k, v) for k, v in zip(keys, values)]
items = list(zip(keys, values))
assert set(keys) == set(store)
assert set(keys) == set(store.keys())
assert set(values) == set(store.values())
Expand Down

0 comments on commit ece1810

Please sign in to comment.