Skip to content

Commit

Permalink
added Resolution to type stub
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderr committed Nov 16, 2022
1 parent 6e9cf49 commit 546a11f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/resolvelib/resolvers.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class ResolutionImpossible(ResolutionError, Generic[RT, CT]):
class ResolutionTooDeep(ResolutionError):
round_count: int

# This should be a NamedTuple, but Python 3.6 has a bug that prevents it.
# https://stackoverflow.com/a/50531189/1376863
class State(tuple, Generic[RT, CT, KT]):
mapping: Mapping[KT, CT]
criteria: Mapping[KT, Criterion[RT, CT, KT]]
backtrack_causes: Collection[RequirementInformation[RT, CT]]

class Resolution(Generic[RT, CT, KT]):
def resolve(
self, requirements: Iterable[RT], max_rounds: int
) -> State[RT, CT, KT]: ...

class Result(Generic[RT, CT, KT]):
mapping: Mapping[KT, CT]
graph: DirectedGraph[Optional[KT]]
Expand Down
8 changes: 5 additions & 3 deletions tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
ResolutionImpossible,
Resolver,
)
from resolvelib.resolvers import Resolution # type: ignore
from resolvelib.resolvers import (
Criterion,
RequirementInformation,
RequirementsConflicted,
Resolution,
)


Expand Down Expand Up @@ -187,7 +187,7 @@ def test_pin_conflict_with_self(monkeypatch, reporter):
],
} # type: Mapping[str, Sequence[Candidate]]

class Provider(AbstractProvider): # AbstractProvider[int, Candidate, str]
class Provider(AbstractProvider): # AbstractProvider[str, Candidate, str]
def identify(self, requirement_or_candidate):
# type: (Union[str, Candidate]) -> str
result = (
Expand Down Expand Up @@ -230,7 +230,9 @@ def is_satisfied_by(self, requirement, candidate):

# patch Resolution._get_updated_criteria to collect rejected states
rejected_criteria = [] # type: List[Criterion]
get_updated_criteria_orig = Resolution._get_updated_criteria
get_updated_criteria_orig = (
Resolution._get_updated_criteria # type: ignore[attr-defined]
)

def get_updated_criteria_patch(self, candidate):
try:
Expand Down

0 comments on commit 546a11f

Please sign in to comment.