Skip to content

Commit

Permalink
Merge collapsible if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Sep 26, 2024
1 parent 1a71987 commit ce95425
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions src/blosc2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1415,14 +1415,13 @@ def compress2(src: object, **kwargs: dict) -> str | bytes:
If an internal error occurred, probably because some
parameter is not a valid parameter.
"""
if kwargs is not None:
if 'cparams' in kwargs:
if len(kwargs) > 1:
raise AttributeError("Cannot pass both cparams and other kwargs already included in CParams")
if isinstance(kwargs.get('cparams'), blosc2.CParams):
kwargs = asdict(kwargs.get('cparams'))
else:
kwargs = kwargs.get('cparams')
if kwargs is not None and 'cparams' in kwargs:
if len(kwargs) > 1:
raise AttributeError("Cannot pass both cparams and other kwargs already included in CParams")
if isinstance(kwargs.get('cparams'), blosc2.CParams):
kwargs = asdict(kwargs.get('cparams'))
else:
kwargs = kwargs.get('cparams')

return blosc2_ext.compress2(src, **kwargs)

Expand Down Expand Up @@ -1476,14 +1475,13 @@ def decompress2(src: object, dst: object | bytearray = None, **kwargs: dict) ->
If the length of :paramref:`src` is smaller than the minimum.
If :paramref:`dst` is not None and its length is 0.
"""
if kwargs is not None:
if 'dparams' in kwargs:
if len(kwargs) > 1:
raise AttributeError("Cannot pass both dparams and other kwargs already included in DParams")
if isinstance(kwargs.get('dparams'), blosc2.DParams):
kwargs = asdict(kwargs.get('dparams'))
else:
kwargs = kwargs.get('dparams')
if kwargs is not None and 'dparams' in kwargs:
if len(kwargs) > 1:
raise AttributeError("Cannot pass both dparams and other kwargs already included in DParams")
if isinstance(kwargs.get('dparams'), blosc2.DParams):
kwargs = asdict(kwargs.get('dparams'))
else:
kwargs = kwargs.get('dparams')

return blosc2_ext.decompress2(src, dst, **kwargs)

Expand Down

0 comments on commit ce95425

Please sign in to comment.