Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
leifdenby committed Aug 16, 2024
1 parent 1226872 commit f03ad4e
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[flake8]
max-line-length = 88
extend-ignore = E203, E713, W604, E231
select = C,E,F,W,B,B950
ignore = E203, E501, W503
per-file-ignores = __init__.py:F401
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ repos:
hooks:
- id: black
- repo: https://github.com/keewis/blackdoc
rev: v0.3.4
rev: v0.3.9
hooks:
- id: blackdoc
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
rev: 6.1.0
hooks:
- id: flake8
4 changes: 2 additions & 2 deletions lagtraj/domain/sources/era5/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _extra_var(self, v):
return da_combined

def __getitem__(self, item):
requested_vars = type(item) == set and item or set(item)
requested_vars = set(item)
available_vars = self._selected_vars or self.data_vars
missing_vars = requested_vars.difference(available_vars)
if len(missing_vars) > 0:
Expand Down Expand Up @@ -292,7 +292,7 @@ def interp(self, kwargs, method="linear", **interp_to):
if np.array(interp_to[d]) in d_vals_array:
slices[d] = interp_to[d]
continue
if type(interp_to[d]) == xr.core.dataarray.DataArray:
if isinstance(interp_to[d], xr.core.dataarray.DataArray):
d_interp_val = interp_to[d].values
else:
d_interp_val = interp_to[d]
Expand Down
8 changes: 5 additions & 3 deletions lagtraj/input_definitions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _check_field(f_name, f_option):
# with the fields `requires` and `choices` can be provided. `requires`
# indicate other validations that must pass and choices are the valid
# choices if they pass
if type(f_option) == dict:
if isinstance(f_option, dict):
if "requires" in f_option and "choices" in f_option:
requirements = f_option["requires"]
satisfied_requirements = {}
Expand Down Expand Up @@ -122,7 +122,9 @@ def _check_field(f_name, f_option):

# here we check whether the parameter was prescribed to have a specific
# type and in that case whether the value provided has the correct type
if type(f_option) == type and type(input_params[f_name]) != f_option:
if isinstance(f_option, type) and not isinstance(
input_params[f_name], f_option
):
raise InvalidInputDefinition(
"Field `{}` should have type {}, but has type `{}`".format(
f_name, f_option, type(input_params[f_name])
Expand All @@ -138,7 +140,7 @@ def _check_field(f_name, f_option):

# choices a given as a list or tuple, so we call `_check_field`
# recursively to see if one of the options fit
if type(f_option) == list or type(f_option) == tuple:
if isinstance(f_option, list) or isinstance(f_option, tuple):
f_options = f_option
exceptions = []
new_val = None
Expand Down
2 changes: 1 addition & 1 deletion lagtraj/trajectory/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main(data_path, trajectory_name):
da_times = _get_times_from_domain(
trajectory_definition=traj_definition, root_data_path=data_path
)
elif type(traj_definition.timestep) == datetime.timedelta:
elif isinstance(traj_definition.timestep, datetime.timedelta):
da_times = _build_times_dataarray(
origin=traj_definition.origin,
duration=traj_definition.duration,
Expand Down
6 changes: 3 additions & 3 deletions lagtraj/utils/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_attributes_dictionary(*args, **kwargs):
"""

def _serialize_item(item, prefix=""):
if type(item) == str:
if isinstance(item, str):
yield (prefix, item)
elif isinstance(item, float) or isinstance(item, int):
yield (prefix, str(item))
Expand All @@ -24,7 +24,7 @@ def _serialize_item(item, prefix=""):
yield (prefix, item.isoformat())
else:
sub_items = []
if type(item) == dict:
if isinstance(item, dict):
sub_items = item.items()
elif (
isinstance(item, xr.Dataset)
Expand All @@ -34,7 +34,7 @@ def _serialize_item(item, prefix=""):
sub_items = item.attrs.items()
# can use isinstance because namedtuple is a kind of tuple and we
# want to save the tuple keys in that case
elif isinstance(item, list) or type(item) == tuple:
elif isinstance(item, list) or isinstance(item, tuple):
sub_items = zip(range(len(item)), item)
else:
# collections.named_tuple has a `_asdict` method to turn it into a dictionary
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ dev =

[flake8]
max-line-length = 88
extend-ignore = E203
extend-ignore = E203, E713, E501, E701
select = C,E,F,W,B,B950
ignore = E203, E501, W503
ignore = E203, E501, W503, W604

[isort]
profile=black
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _parse_readme_cli_commands():

lines = [line.replace("$>", "").strip() for line in lines]

cli_commands = list(filter(lambda l: "python -m lagtraj" in l, lines))
cli_commands = list(filter(lambda line: "python -m lagtraj" in line, lines))

return cli_commands

Expand Down

0 comments on commit f03ad4e

Please sign in to comment.