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

@@ -119,10 +119,12 @@ class PokerHand:
For example: "6S 4C KC AS TH"
"""
if not isinstance(hand, str):
raise TypeError(f"Hand should be of type 'str': {hand!r}")
msg = f"Hand should be of type 'str': {hand!r}"
raise TypeError(msg)
# split removes duplicate whitespaces so no need of strip
if len(hand.split(" ")) != 5:
raise ValueError(f"Hand should contain only 5 cards: {hand!r}")
msg = f"Hand should contain only 5 cards: {hand!r}"
raise ValueError(msg)
self._hand = hand
self._first_pair = 0
self._second_pair = 0

View File

@@ -73,7 +73,8 @@ def solution(gon_side: int = 5) -> int:
if is_magic_gon(numbers):
return int("".join(str(n) for n in numbers))
raise ValueError(f"Magic {gon_side}-gon ring is impossible")
msg = f"Magic {gon_side}-gon ring is impossible"
raise ValueError(msg)
def generate_gon_ring(gon_side: int, perm: list[int]) -> list[int]:

View File

@@ -26,10 +26,7 @@ def is_prime(number: int) -> bool:
False
"""
for divisor in range(2, isqrt(number) + 1):
if number % divisor == 0:
return False
return True
return all(number % divisor != 0 for divisor in range(2, isqrt(number) + 1))
def solution(max_prime: int = 10**6) -> int: