Skip to content

Commit ece1810

Browse files
Fix deepsource.io issues (#1080)
* 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 <[email protected]>
1 parent 4b83302 commit ece1810

File tree

8 files changed

+15
-13
lines changed

8 files changed

+15
-13
lines changed

docs/release.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ Documentation
1919
Maintenance
2020
~~~~~~~~~~~
2121

22+
* Fix a few DeepSource.io alerts
23+
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>` :issue:`1080`.
24+
2225
* Fix spelling.
2326
By :user:`Dimitri Papadopoulos Orfanos <DimitriPapadopoulos>`, :issue:`1073`.
2427

25-
2628
.. _release_2.12.0:
2729

2830
2.12.0

zarr/convenience.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ def open_consolidated(store: StoreLike, metadata_key=".zmetadata", mode="r+", **
12791279
"""
12801280

12811281
# normalize parameters
1282-
zarr_version = kwargs.get('zarr_version', None)
1282+
zarr_version = kwargs.get('zarr_version')
12831283
store = normalize_store_arg(store, storage_options=kwargs.get("storage_options"), mode=mode,
12841284
zarr_version=zarr_version)
12851285
if mode not in {'r', 'r+'}:

zarr/hierarchy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,7 @@ def open_group(store=None, mode='a', cache_attrs=True, synchronizer=None, path=N
13271327
storage_options=storage_options,
13281328
mode=mode,
13291329
zarr_version=zarr_version)
1330-
if not getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION) == zarr_version:
1330+
if getattr(chunk_store, '_store_version', DEFAULT_ZARR_VERSION) != zarr_version:
13311331
raise ValueError(
13321332
"zarr_version of store and chunk_store must match"
13331333
)

zarr/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ def __contains__(self, key):
14131413
return key in self.map
14141414

14151415
def __eq__(self, other):
1416-
return (type(self) == type(other) and self.map == other.map
1416+
return (type(self) is type(other) and self.map == other.map
14171417
and self.mode == other.mode)
14181418

14191419
def keys(self):

zarr/tests/test_convenience.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
)
4646
from zarr.tests.util import have_fsspec
4747

48-
_VERSIONS = v3_api_available and (2, 3) or (2,)
48+
_VERSIONS = ((2, 3) if v3_api_available else (2, ))
4949

5050

5151
def _init_creation_kwargs(zarr_version):

zarr/tests/test_creation.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
from zarr._storage.v3 import DirectoryStoreV3, KVStoreV3
2222
from zarr.sync import ThreadSynchronizer
2323

24-
_VERSIONS = v3_api_available and (None, 2, 3) or (None, 2)
25-
_VERSIONS2 = v3_api_available and (2, 3) or (2,)
24+
_VERSIONS = ((None, 2, 3) if v3_api_available else (None, 2))
25+
_VERSIONS2 = ((2, 3) if v3_api_available else (2, ))
2626

2727

2828
# something bcolz-like
@@ -430,7 +430,7 @@ def test_empty_like(zarr_version):
430430
z = empty(100, chunks=10, dtype='f4', compressor=Zlib(5),
431431
order='F', **kwargs)
432432
# zarr_version will be inferred from z, but have to specify a path in v3
433-
z2 = empty_like(z, path=kwargs.get('path', None))
433+
z2 = empty_like(z, path=kwargs.get('path'))
434434
assert z.shape == z2.shape
435435
assert z.chunks == z2.chunks
436436
assert z.dtype == z2.dtype
@@ -479,7 +479,7 @@ def test_zeros_like(zarr_version):
479479
# zarr array
480480
z = zeros(100, chunks=10, dtype='f4', compressor=Zlib(5),
481481
order='F', **kwargs)
482-
z2 = zeros_like(z, path=kwargs.get('path', None))
482+
z2 = zeros_like(z, path=kwargs.get('path'))
483483
assert z.shape == z2.shape
484484
assert z.chunks == z2.chunks
485485
assert z.dtype == z2.dtype
@@ -506,7 +506,7 @@ def test_ones_like(zarr_version):
506506
# zarr array
507507
z = ones(100, chunks=10, dtype='f4', compressor=Zlib(5),
508508
order='F', **kwargs)
509-
z2 = ones_like(z, path=kwargs.get('path', None))
509+
z2 = ones_like(z, path=kwargs.get('path'))
510510
assert z.shape == z2.shape
511511
assert z.chunks == z2.chunks
512512
assert z.dtype == z2.dtype
@@ -533,7 +533,7 @@ def test_full_like(zarr_version):
533533

534534
z = full(100, chunks=10, dtype='f4', compressor=Zlib(5),
535535
fill_value=42, order='F', **kwargs)
536-
z2 = full_like(z, path=kwargs.get('path', None))
536+
z2 = full_like(z, path=kwargs.get('path'))
537537
assert z.shape == z2.shape
538538
assert z.chunks == z2.chunks
539539
assert z.dtype == z2.dtype

zarr/tests/test_hierarchy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
from zarr.tests.util import skip_test_env_var, have_fsspec, abs_container
3636

3737

38-
_VERSIONS = v3_api_available and (2, 3) or (2,)
38+
_VERSIONS = ((2, 3) if v3_api_available else (2, ))
3939

4040
# noinspection PyStatementEffect
4141

zarr/tests/test_storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ def test_iterators_with_prefix(self):
24002400
assert 4 == len(store)
24012401
keys = [prefix + 'a', prefix + 'b', prefix + 'c/d', prefix + 'c/e/f']
24022402
values = [b'aaa', b'bbb', b'ddd', b'fff']
2403-
items = [(k, v) for k, v in zip(keys, values)]
2403+
items = list(zip(keys, values))
24042404
assert set(keys) == set(store)
24052405
assert set(keys) == set(store.keys())
24062406
assert set(values) == set(store.values())

0 commit comments

Comments
 (0)