Skip to content

Commit

Permalink
QA/Ruff: Enable flake8-bugbear (B) rules
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 22, 2023
1 parent 0cde4ff commit 7108824
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,12 @@ line-length = 120

[tool.ruff]
line-length = 120

select = [
# Bandit
"S",
# Bugbear
"B",
# isort
"I",
# Pycodestyle
Expand All @@ -245,11 +248,18 @@ select = [
"F",
]

extend-ignore = [
# zip() without an explicit strict= parameter.
"B905",
]


[tool.ruff.per-file-ignores]
"**/__init__.py" = ["F401"]
"wetterdienst/__init__.py" = ["E402"]
"tests/*" = ["S101"]
"tests/provider/dwd/observation/test_available_datasets.py" = ["E402"]
"wetterdienst/__init__.py" = ["E402"]
"wetterdienst/ui/restapi.py" = ["B008"]

[tool.poe.tasks]
install_dev = "poetry install --with=test,dev,docs -E mpl -E ipython -E sql -E export -E duckdb -E influxdb -E cratedb -E mysql -E postgresql -E radar -E bufr -E restapi -E explorer -E bufr -E interpolation"
Expand Down
2 changes: 1 addition & 1 deletion tools/citation.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def generate_cff_file(width: int = 79):
Citation(cffstr=cff_serialisat).validate()
except ValidationError as e:
log.warning(e)
raise SystemExit(1)
raise SystemExit(1) from e
CFF.write_text(data=cff_serialisat)


Expand Down
6 changes: 3 additions & 3 deletions wetterdienst/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def resolve(cls, provider: str, network: str):
try:
return cls[provider][network.upper()].load()
except AttributeError as ex:
raise KeyError(ex)
raise KeyError(ex) from ex

@classmethod
def get_provider_names(cls):
Expand Down Expand Up @@ -138,8 +138,8 @@ def __new__(cls, provider: str, network: str):
if not api:
raise KeyError

except (InvalidEnumeration, KeyError):
raise ProviderError(f"No API available for provider {provider} and network {network}")
except (InvalidEnumeration, KeyError) as ex:
raise ProviderError(f"No API available for provider {provider} and network {network}") from ex

return api

Expand Down
4 changes: 2 additions & 2 deletions wetterdienst/core/scalar/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ def _get_latlon_by_station_id(self, station_id: str) -> Tuple[float, float]:
lat, lon = stations.loc[
stations[Columns.STATION_ID.value] == station_id, [Columns.LATITUDE.value, Columns.LONGITUDE.value]
].values.flatten()
except ValueError:
raise StationNotFoundError(f"no station found for {station_id}")
except ValueError as ex:
raise StationNotFoundError(f"no station found for {station_id}") from ex

return lat, lon
4 changes: 2 additions & 2 deletions wetterdienst/provider/dwd/observation/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def __download_climate_observations_data(remote_file: str) -> bytes:
file = download_file(remote_file, ttl=CacheExpiry.FIVE_MINUTES)
except InvalidURL as e:
raise InvalidURL(f"Error: the station data {remote_file} could not be reached.") from e
except Exception:
raise FailedDownload(f"Download failed for {remote_file}")
except Exception as ex:
raise FailedDownload(f"Download failed for {remote_file}") from ex

try:
zfs = ZipFileSystem(file)
Expand Down
8 changes: 4 additions & 4 deletions wetterdienst/util/enumeration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,17 @@ def parse_enumeration_from_template(
raise ValueError()
else:
enum_parsed = intermediate(enum_)
except ValueError:
raise InvalidEnumeration(f"{enum_} could not be parsed from {intermediate.__name__}.")
except ValueError as ex:
raise InvalidEnumeration(f"{enum_} could not be parsed from {intermediate.__name__}.") from ex

if base:
try:
enum_parsed = base[enum_parsed.name]
except (KeyError, AttributeError):
try:
enum_parsed = base(enum_parsed)
except ValueError:
raise InvalidEnumeration(f"{enum_parsed} could not be parsed from {base.__name__}.")
except ValueError as ex:
raise InvalidEnumeration(f"{enum_parsed} could not be parsed from {base.__name__}.") from ex

return enum_parsed

Expand Down

0 comments on commit 7108824

Please sign in to comment.