11"""Module defining the Problem and Solution base classes and related objects."""
22from abc import ABC , abstractmethod
3+ from collections .abc import Callable
34from dataclasses import dataclass
45from functools import wraps
56from importlib .metadata import entry_points
67from inspect import Parameter , Signature , signature
78from itertools import chain
9+ from math import inf , isnan
810from pathlib import Path
911from 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
3229from pydantic .main import BaseModel
3330from pydantic_core import CoreSchema
3431from 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
5040class Instance (Encodable , ABC ):
@@ -72,12 +62,12 @@ def validate_instance(self) -> None:
7262P = 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
507497SelfRef = AttributeReferenceMaker ("self" )
0 commit comments