Add more ruff rules (#8767)

* Add more ruff rules

* Add more ruff rules

* pre-commit: Update ruff v0.0.269 -> v0.0.270

* Apply suggestions from code review

* Fix doctest

* Fix doctest (ignore whitespace)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Christian Clauss
2023-05-26 09:34:17 +02:00
committed by GitHub
parent dd3b499bfa
commit 4b79d771cd
67 changed files with 349 additions and 223 deletions

View File

@ -65,7 +65,8 @@ def get_barcode(barcode: str) -> int:
ValueError: Barcode 'dwefgiweuf' has alphabetic characters.
"""
if str(barcode).isalpha():
raise ValueError(f"Barcode '{barcode}' has alphabetic characters.")
msg = f"Barcode '{barcode}' has alphabetic characters."
raise ValueError(msg)
elif int(barcode) < 0:
raise ValueError("The entered barcode has a negative value. Try again.")
else:

View File

@ -17,7 +17,7 @@ def capitalize(sentence: str) -> str:
"""
if not sentence:
return ""
lower_to_upper = {lc: uc for lc, uc in zip(ascii_lowercase, ascii_uppercase)}
lower_to_upper = dict(zip(ascii_lowercase, ascii_uppercase))
return lower_to_upper.get(sentence[0], sentence[0]) + sentence[1:]

View File

@ -48,7 +48,8 @@ def is_spain_national_id(spanish_id: str) -> bool:
"""
if not isinstance(spanish_id, str):
raise TypeError(f"Expected string as input, found {type(spanish_id).__name__}")
msg = f"Expected string as input, found {type(spanish_id).__name__}"
raise TypeError(msg)
spanish_id_clean = spanish_id.replace("-", "").upper()
if len(spanish_id_clean) != 9:

View File

@ -27,11 +27,11 @@ def snake_to_camel_case(input_str: str, use_pascal: bool = False) -> str:
"""
if not isinstance(input_str, str):
raise ValueError(f"Expected string as input, found {type(input_str)}")
msg = f"Expected string as input, found {type(input_str)}"
raise ValueError(msg)
if not isinstance(use_pascal, bool):
raise ValueError(
f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
)
msg = f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
raise ValueError(msg)
words = input_str.split("_")