Skip to content

Commit 481d491

Browse files
committed
fix linting issues
1 parent 27222ea commit 481d491

7 files changed

Lines changed: 57 additions & 184 deletions

File tree

.flake8

Lines changed: 0 additions & 16 deletions
This file was deleted.

algobattle/battle.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,13 @@ class Config(Battle.Config):
705705
"""Number of fights that will be fought."""
706706
weighting: Annotated[float, Ge(0)] = 1.1
707707
"""How much each successive fight should be weighted more than the previous."""
708-
scores: set[Role] = {Role.generator, Role.solver}
708+
scores: set[Role] = {Role.generator, Role.solver} # noqa: RUF012
709709
"""Who to show each fight's scores to."""
710-
instances: set[Role] = {Role.generator, Role.solver}
710+
instances: set[Role] = {Role.generator, Role.solver} # noqa: RUF012
711711
"""Who to show the instances to."""
712-
generator_solutions: set[Role] = {Role.generator}
712+
generator_solutions: set[Role] = {Role.generator} # noqa: RUF012
713713
"""Who to show the generator's solutions to, if the problem requires them."""
714-
solver_solutions: set[Role] = {Role.solver}
714+
solver_solutions: set[Role] = {Role.solver} # noqa: RUF012
715715
"""Who to show the solver's solutions to."""
716716

717717
class UiData(Battle.UiData):

algobattle/problem.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,40 @@
11
"""Module defining the Problem and Solution base classes and related objects."""
22
from abc import ABC, abstractmethod
3+
from collections.abc import Callable
34
from dataclasses import dataclass
45
from functools import wraps
56
from importlib.metadata import entry_points
67
from inspect import Parameter, Signature, signature
78
from itertools import chain
9+
from math import inf, isnan
810
from pathlib import Path
911
from typing import (
1012
TYPE_CHECKING,
1113
Any,
12-
Callable,
1314
ClassVar,
15+
Generic,
1416
Literal,
1517
ParamSpec,
1618
Protocol,
1719
Self,
18-
Generic,
1920
TypeVar,
20-
overload,
2121
cast,
2222
get_args,
23+
overload,
2324
runtime_checkable,
2425
)
25-
from math import inf, isnan
26-
from annotated_types import GroupedMetadata
2726

28-
from pydantic import (
29-
GetCoreSchemaHandler,
30-
ValidationInfo,
31-
)
27+
from annotated_types import GroupedMetadata
28+
from pydantic import GetCoreSchemaHandler, ValidationInfo
3229
from pydantic.main import BaseModel
3330
from pydantic_core import CoreSchema
3431
from pydantic_core.core_schema import (
32+
ValidatorFunctionWrapHandler,
3533
with_info_after_validator_function,
3634
with_info_wrap_validator_function,
37-
ValidatorFunctionWrapHandler,
3835
)
3936

40-
from algobattle.util import (
41-
EncodableBase,
42-
EncodableModel,
43-
EncodableModelBase,
44-
Role,
45-
Encodable,
46-
import_file_as_module,
47-
)
37+
from algobattle.util import Encodable, EncodableBase, EncodableModel, EncodableModelBase, Role, import_file_as_module
4838

4939

5040
class Instance(Encodable, ABC):
@@ -72,12 +62,12 @@ def validate_instance(self) -> None:
7262
P = ParamSpec("P")
7363

7464

75-
class Solution(EncodableBase, Generic[InstanceT], ABC):
65+
class Solution(EncodableBase, ABC, Generic[InstanceT]):
7666
"""A proposed solution for an instance of this problem."""
7767

7868
@classmethod
7969
@abstractmethod
80-
def decode(cls, source: Path, max_size: int, role: Role, instance: InstanceT) -> Self: # noqa: D102
70+
def decode(cls, source: Path, max_size: int, role: Role, instance: InstanceT) -> Self:
8171
raise NotImplementedError
8272

8373
def validate_solution(self, instance: InstanceT, role: Role) -> None:
@@ -230,7 +220,7 @@ class Problem:
230220
"""The definition of a problem."""
231221

232222
@overload
233-
def __init__( # noqa: D107
223+
def __init__(
234224
self,
235225
*,
236226
name: str,
@@ -244,7 +234,7 @@ def __init__( # noqa: D107
244234
...
245235

246236
@overload
247-
def __init__( # noqa: D107
237+
def __init__(
248238
self,
249239
*,
250240
name: str,
@@ -295,7 +285,7 @@ def __init__(
295285
self.test_instance = test_instance
296286
self._problems[name] = self
297287

298-
__slots__ = ("name", "instance_cls", "solution_cls", "min_size", "with_solution", "score_function", "test_instance")
288+
__slots__ = ("instance_cls", "min_size", "name", "score_function", "solution_cls", "test_instance", "with_solution")
299289
_problems: ClassVar[dict[str, Self]] = {}
300290

301291
@overload
@@ -376,7 +366,7 @@ def load(cls, name: str, file: Path | None = None) -> Self:
376366
case [e]:
377367
loaded: object = e.load()
378368
if not isinstance(loaded, cls):
379-
raise ValueError(
369+
raise ValueError( # noqa: TRY004
380370
f"The entrypoint '{name}' doesn't point to a problem but a {loaded.__class__.__qualname__}."
381371
)
382372
return loaded
@@ -500,8 +490,8 @@ class AttributeReferenceMaker:
500490

501491
_attr_ref_maker_model: ModelReference
502492

503-
def __getattr__(self, __name: str) -> AttributeReference:
504-
return AttributeReference(self._attr_ref_maker_model, __name)
493+
def __getattr__(self, name: str, /) -> AttributeReference:
494+
return AttributeReference(self._attr_ref_maker_model, name)
505495

506496

507497
SelfRef = AttributeReferenceMaker("self")

algobattle/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def edge_set(self) -> set[tuple[Vertex, Vertex]]:
438438
"""The set of edges in this graph."""
439439
return set(self.edges)
440440

441-
@cache
441+
@cache # noqa: B019
442442
def neighbors(self, vertex: Vertex, direction: Literal["all", "outgoing", "incoming"] = "all") -> set[Vertex]:
443443
"""The neighbors of a vertex."""
444444
res = set[Vertex]()
@@ -474,7 +474,7 @@ def edge_set(self) -> set[tuple[Vertex, Vertex]]:
474474
"""
475475
return set(self.edges) | {(v, u) for (u, v) in self.edges}
476476

477-
@cache
477+
@cache # noqa: B019
478478
def neighbors(self, vertex: Vertex, direction: Literal["all", "outgoing", "incoming"] = "all") -> set[Vertex]:
479479
"""The neighbors of a vertex."""
480480
# more efficient specialization
@@ -515,7 +515,7 @@ def edges_with_weights(self) -> Iterator[tuple[tuple[Vertex, Vertex], Weight]]:
515515
"""Iterate over all edges and their weights."""
516516
return zip(self.edges, self.edge_weights, strict=True)
517517

518-
@cache
518+
@cache # noqa: B019
519519
def weight(self, edge: Edge | tuple[Vertex, Vertex]) -> Weight:
520520
"""Returns the weight of an edge.
521521

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ Repository = "https://github.com/Benezivas/algobattle"
3939

4040
[project.optional-dependencies]
4141
dev = [
42-
"black>=23.12.1",
43-
"flake8>=6.1.0",
44-
"flake8-docstrings>=1.7.0",
42+
"ruff>=0.13.2",
4543
"mkdocs>=1.5.3",
4644
"mkdocs-material>=9.5.3",
4745
"pymdown-extensions>=10.7",
@@ -55,7 +53,7 @@ algobattle = "algobattle.cli:app"
5553
[tool.ruff]
5654
preview = true
5755
line-length = 120
58-
exclude = ["docs"]
56+
exclude = ["docs/src"]
5957

6058
[tool.ruff.lint]
6159
select = [
@@ -104,7 +102,7 @@ split-on-trailing-comma = false
104102
combine-as-imports = true
105103

106104
[tool.pyright]
107-
exclude = ["docs"]
105+
exclude = [".venv", "docs"]
108106
typeCheckingMode = "standard"
109107
disableBytesTypePromotions = true
110108
strictDictionaryInference = true

tests/testsproblem/problem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"""Problem class built for tests."""
22

33
from typing import Any
4-
from algobattle.problem import Problem, InstanceModel, SolutionModel
4+
5+
from algobattle.problem import InstanceModel, Problem, SolutionModel
56
from algobattle.util import Role, ValidationError
67

78

0 commit comments

Comments
 (0)