From 4caf02a2cb31a1b4d01cf27a52f1feedc5116c6c Mon Sep 17 00:00:00 2001 From: Tyler Yep Date: Fri, 29 Mar 2024 15:20:10 -0700 Subject: [PATCH] Update Ruff version --- .pre-commit-config.yaml | 2 +- ruff.toml | 30 ++++++++++++++---------------- wolfbot/algorithms/expectimax.py | 8 +++++--- wolfbot/const.py | 5 ++++- wolfbot/enums.py | 6 ++++-- wolfbot/game_utils.py | 8 ++++++-- wolfbot/roles/werewolf/minion.py | 6 ++++-- wolfbot/roles/werewolf/tanner.py | 6 ++++-- wolfbot/roles/werewolf/wolf.py | 6 ++++-- wolfbot/solvers/cached.py | 6 +++++- wolfbot/solvers/relaxed.py | 5 ++++- wolfbot/solvers/state.py | 8 +++++--- wolfbot/solvers/switching.py | 6 +++++- 13 files changed, 65 insertions(+), 37 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b9bdb4c..e7ce53e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ ci: skip: [mypy, pytest] repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.3.4 hooks: - id: ruff args: [--fix] diff --git a/ruff.toml b/ruff.toml index a77ee2c..fffa7ec 100644 --- a/ruff.toml +++ b/ruff.toml @@ -1,8 +1,8 @@ target-version = "py312" -select = ["ALL"] -ignore = [ - "ANN101", # Missing type annotation for `self` in method - "ANN102", # Missing type annotation for `cls` in classmethod +lint.select = ["ALL"] +lint.ignore = [ + "ANN101", # Missing type annotation for `self` in method + "ANN102", # Missing type annotation for `cls` in classmethod "ANN401", # Dynamically typed expressions (typing.Any) are disallowed "C901", # function is too complex (12 > 10) "COM812", # Trailing comma missing @@ -15,27 +15,25 @@ ignore = [ "FBT003", # Boolean positional value in function call "FIX002", # Line contains TODO "ISC001", # Isort - "PLR0911", # Too many return statements (11 > 6) + "PLR0911", # Too many return statements (11 > 6) "PLR2004", # Magic value used in comparison, consider replacing 2 with a constant variable - "PLR0912", # Too many branches + "PLR0912", # Too many branches "PLR0913", # Too many arguments to function call "PLR0915", # Too many statements "S101", # Use of `assert` detected "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes "T201", # print() found "T203", # pprint() found - "TCH001", # Move application import into a type-checking block - "TCH003", # Move standard library import into a type-checking block - "TD002", # Missing author in TODO; try: `# TODO(): ...` - "TD003", # Missing issue link on the line following this TODO - "TD005", # Missing issue description after `TODO` - "TRY003", # Avoid specifying long messages outside the exception class + "TD002", # Missing author in TODO; try: `# TODO(): ...` + "TD003", # Missing issue link on the line following this TODO + "TD005", # Missing issue description after `TODO` + "TRY003", # Avoid specifying long messages outside the exception class # WolfBot-specific ignores - "ARG001", # Unused function argument - "ARG004", # Unused static method argument - "PT004", # Fixture `override_random` does not return anything, add leading underscore + "ARG001", # Unused function argument + "ARG004", # Unused static method argument + "PT004", # Fixture `override_random` does not return anything, add leading underscore ] -[flake8-pytest-style] +[lint.flake8-pytest-style] fixture-parentheses = false diff --git a/wolfbot/algorithms/expectimax.py b/wolfbot/algorithms/expectimax.py index 7e7fc10..354163c 100644 --- a/wolfbot/algorithms/expectimax.py +++ b/wolfbot/algorithms/expectimax.py @@ -1,11 +1,13 @@ from __future__ import annotations import random -from typing import Any +from typing import TYPE_CHECKING, Any from wolfbot import const -from wolfbot.solvers import SolverState -from wolfbot.statements import Statement + +if TYPE_CHECKING: + from wolfbot.solvers import SolverState + from wolfbot.statements import Statement def expectimax( diff --git a/wolfbot/const.py b/wolfbot/const.py index 1f4e977..376516b 100644 --- a/wolfbot/const.py +++ b/wolfbot/const.py @@ -6,11 +6,14 @@ import sys from collections import Counter from pathlib import Path -from types import ModuleType +from typing import TYPE_CHECKING from wolfbot.enums import Role, Solver from wolfbot.log import logger +if TYPE_CHECKING: + from types import ModuleType + def init_program(is_tests: bool) -> argparse.Namespace: """Command Line Arguments""" diff --git a/wolfbot/enums.py b/wolfbot/enums.py index 107fab2..de88d30 100644 --- a/wolfbot/enums.py +++ b/wolfbot/enums.py @@ -1,9 +1,11 @@ from __future__ import annotations import functools -from collections.abc import Callable from enum import Enum, IntEnum, auto, unique -from typing import Any, TypeVar, cast, override +from typing import TYPE_CHECKING, Any, TypeVar, cast, override + +if TYPE_CHECKING: + from collections.abc import Callable T = TypeVar("T") CACHED_FUNCTIONS = set() diff --git a/wolfbot/game_utils.py b/wolfbot/game_utils.py index 4d34561..adff87c 100644 --- a/wolfbot/game_utils.py +++ b/wolfbot/game_utils.py @@ -2,12 +2,16 @@ import logging import random -from collections.abc import Sequence +from typing import TYPE_CHECKING from wolfbot import const -from wolfbot.enums import Role from wolfbot.log import logger +if TYPE_CHECKING: + from collections.abc import Sequence + + from wolfbot.enums import Role + def print_roles( game_roles: Sequence[Role], tag: str, log_level: int = logging.DEBUG diff --git a/wolfbot/roles/werewolf/minion.py b/wolfbot/roles/werewolf/minion.py index bb46709..031b275 100644 --- a/wolfbot/roles/werewolf/minion.py +++ b/wolfbot/roles/werewolf/minion.py @@ -1,7 +1,7 @@ from __future__ import annotations import random -from typing import Any, Self, override +from typing import TYPE_CHECKING, Any, Self, override from wolfbot import const from wolfbot.enums import Role, lru_cache @@ -15,7 +15,9 @@ get_wolf_statements_random, ) from wolfbot.solvers import switching_solver as solver -from wolfbot.statements import KnowledgeBase, Statement + +if TYPE_CHECKING: + from wolfbot.statements import KnowledgeBase, Statement class Minion(Player): diff --git a/wolfbot/roles/werewolf/tanner.py b/wolfbot/roles/werewolf/tanner.py index ad6ad0f..8dc8712 100644 --- a/wolfbot/roles/werewolf/tanner.py +++ b/wolfbot/roles/werewolf/tanner.py @@ -1,7 +1,7 @@ from __future__ import annotations import random -from typing import Self, override +from typing import TYPE_CHECKING, Self, override from wolfbot import const from wolfbot.enums import Role, lru_cache @@ -12,7 +12,9 @@ get_wolf_statements_random, ) from wolfbot.solvers import switching_solver as solver -from wolfbot.statements import KnowledgeBase, Statement + +if TYPE_CHECKING: + from wolfbot.statements import KnowledgeBase, Statement class Tanner(Player): diff --git a/wolfbot/roles/werewolf/wolf.py b/wolfbot/roles/werewolf/wolf.py index d010d9f..ca6206a 100644 --- a/wolfbot/roles/werewolf/wolf.py +++ b/wolfbot/roles/werewolf/wolf.py @@ -1,7 +1,7 @@ from __future__ import annotations import random -from typing import Any, Self, override +from typing import TYPE_CHECKING, Any, Self, override from wolfbot import const from wolfbot.enums import Role, lru_cache @@ -17,7 +17,9 @@ get_wolf_statements_random, ) from wolfbot.solvers import switching_solver as solver -from wolfbot.statements import KnowledgeBase, Statement + +if TYPE_CHECKING: + from wolfbot.statements import KnowledgeBase, Statement class Wolf(Player): diff --git a/wolfbot/solvers/cached.py b/wolfbot/solvers/cached.py index 9b40203..b22a6ad 100644 --- a/wolfbot/solvers/cached.py +++ b/wolfbot/solvers/cached.py @@ -1,7 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from wolfbot.solvers.state import SolverState -from wolfbot.statements import Statement + +if TYPE_CHECKING: + from wolfbot.statements import Statement def cached_solver(statements: tuple[Statement, ...]) -> int: diff --git a/wolfbot/solvers/relaxed.py b/wolfbot/solvers/relaxed.py index ecbbe15..8c9c1f8 100644 --- a/wolfbot/solvers/relaxed.py +++ b/wolfbot/solvers/relaxed.py @@ -1,10 +1,13 @@ from __future__ import annotations import heapq +from typing import TYPE_CHECKING from wolfbot import const from wolfbot.solvers.state import SolverState -from wolfbot.statements import Statement + +if TYPE_CHECKING: + from wolfbot.statements import Statement def relaxed_solver( diff --git a/wolfbot/solvers/state.py b/wolfbot/solvers/state.py index 97a4a7a..5d8c35d 100644 --- a/wolfbot/solvers/state.py +++ b/wolfbot/solvers/state.py @@ -3,12 +3,14 @@ import shutil from dataclasses import dataclass, field from functools import total_ordering -from typing import override +from typing import TYPE_CHECKING, override from wolfbot import const -from wolfbot.enums import Role from wolfbot.log import formatter -from wolfbot.statements import Statement, Switch + +if TYPE_CHECKING: + from wolfbot.enums import Role + from wolfbot.statements import Statement, Switch @total_ordering diff --git a/wolfbot/solvers/switching.py b/wolfbot/solvers/switching.py index 481d612..5f6f235 100644 --- a/wolfbot/solvers/switching.py +++ b/wolfbot/solvers/switching.py @@ -1,7 +1,11 @@ from __future__ import annotations +from typing import TYPE_CHECKING + from wolfbot.solvers.state import SolverState -from wolfbot.statements import Statement + +if TYPE_CHECKING: + from wolfbot.statements import Statement def switching_solver(