Skip to content

Commit

Permalink
fix: change the order of generics
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Aug 29, 2023
1 parent 9c01897 commit e33490b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/resolvelib/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from _typeshed import SupportsRichComparison


class AbstractProvider(Generic[KT, RT, CT]):
class AbstractProvider(Generic[RT, CT, KT]):
"""Delegate class to provide the required interface for the resolver."""

def identify(self, requirement_or_candidate: RT | CT) -> KT:
Expand Down
6 changes: 3 additions & 3 deletions src/resolvelib/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)


class BaseReporter(Generic[KT, RT, CT]):
class BaseReporter(Generic[RT, CT, KT]):
"""Delegate class to provider progress reporting for the resolver."""

def starting(self) -> None:
Expand All @@ -25,14 +25,14 @@ def starting_round(self, index: int) -> None:
The index is zero-based.
"""

def ending_round(self, index: int, state: State[KT, RT, CT]) -> None:
def ending_round(self, index: int, state: State[RT, CT, KT]) -> None:
"""Called before each round of resolution ends.
This is NOT called if the resolution ends at this round. Use `ending`
if you want to report finalization. The index is zero-based.
"""

def ending(self, state: State[KT, RT, CT]) -> None:
def ending(self, state: State[RT, CT, KT]) -> None:
"""Called before the resolution ends successfully."""

def adding_requirement(self, requirement: RT, parent: CT | None) -> None:
Expand Down
28 changes: 14 additions & 14 deletions src/resolvelib/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
if TYPE_CHECKING:
from _typeshed import SupportsRichComparison

class Result(NamedTuple, Generic[KT, RT, CT]):
class Result(NamedTuple, Generic[RT, CT, KT]):
mapping: Mapping[KT, CT]
graph: DirectedGraph[KT | None]
criteria: Mapping[KT, Criterion[RT, CT]]
Expand Down Expand Up @@ -89,7 +89,7 @@ def __init__(self, round_count: int) -> None:
self.round_count = round_count


class Resolution(Generic[KT, RT, CT]):
class Resolution(Generic[RT, CT, KT]):
"""Stateful resolution object.
This is designed as a one-off object that holds information to kick start
Expand All @@ -98,15 +98,15 @@ class Resolution(Generic[KT, RT, CT]):

def __init__(
self,
provider: AbstractProvider[KT, RT, CT],
reporter: BaseReporter[KT, RT, CT],
provider: AbstractProvider[RT, CT, KT],
reporter: BaseReporter[RT, CT, KT],
) -> None:
self._p = provider
self._r = reporter
self._states: list[State[KT, RT, CT]] = []
self._states: list[State[RT, CT, KT]] = []

@property
def state(self) -> State[KT, RT, CT]:
def state(self) -> State[RT, CT, KT]:
try:
return self._states[-1]
except IndexError:
Expand Down Expand Up @@ -383,7 +383,7 @@ def _patch_criteria() -> bool:

def resolve(
self, requirements: Iterable[RT], max_rounds: int
) -> State[KT, RT, CT]:
) -> State[RT, CT, KT]:
if self._states:
raise RuntimeError("already resolved")

Expand Down Expand Up @@ -487,7 +487,7 @@ def _has_route_to_root(
return False


def _build_result(state: State[KT, RT, CT]) -> Result[KT, RT, CT]:
def _build_result(state: State[RT, CT, KT]) -> Result[RT, CT, KT]:
mapping = state.mapping
all_keys: dict[int, KT | None] = {id(v): k for k, v in mapping.items()}
all_keys[id(None)] = None
Expand Down Expand Up @@ -517,22 +517,22 @@ def _build_result(state: State[KT, RT, CT]) -> Result[KT, RT, CT]:
)


class AbstractResolver(Generic[KT, RT, CT]):
class AbstractResolver(Generic[RT, CT, KT]):
"""The thing that performs the actual resolution work."""

base_exception = Exception

def __init__(
self,
provider: AbstractProvider[KT, RT, CT],
reporter: BaseReporter[KT, RT, CT],
provider: AbstractProvider[RT, CT, KT],
reporter: BaseReporter[RT, CT, KT],
) -> None:
self.provider = provider
self.reporter = reporter

def resolve(
self, requirements: Iterable[RT], **kwargs: Any
) -> Result[KT, RT, CT]:
) -> Result[RT, CT, KT]:
"""Take a collection of constraints, spit out the resolution result.
This returns a representation of the final resolution state, with one
Expand All @@ -547,7 +547,7 @@ def resolve(
raise NotImplementedError


class Resolver(AbstractResolver[KT, RT, CT]):
class Resolver(AbstractResolver[RT, CT, KT]):
"""The thing that performs the actual resolution work."""

base_exception = ResolverException
Expand All @@ -556,7 +556,7 @@ def resolve( # type: ignore[override]
self,
requirements: Iterable[RT],
max_rounds: int = 100,
) -> Result[KT, RT, CT]:
) -> Result[RT, CT, KT]:
"""Take a collection of constraints, spit out the resolution result.
The return value is a representation to the final resolution result. It
Expand Down
4 changes: 2 additions & 2 deletions src/resolvelib/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class RequirementInformation(NamedTuple, Generic[RT, CT]):
requirement: RT
parent: CT | None

class State(NamedTuple, Generic[KT, RT, CT]):
class State(NamedTuple, Generic[RT, CT, KT]):
"""Resolution state in a round."""

mapping: dict[KT, CT]
Expand Down Expand Up @@ -110,7 +110,7 @@ def iter_parents(self, key: KT) -> Iterator[KT]:
return iter(self._backwards[key])


class IteratorMapping(Mapping[KT, Iterator[CT]], Generic[KT, RT, CT]):
class IteratorMapping(Mapping[KT, Iterator[CT]], Generic[RT, CT, KT]):
def __init__(
self,
mapping: Mapping[KT, RT],
Expand Down

0 comments on commit e33490b

Please sign in to comment.