diff --git a/src/resolvelib/resolvers.pyi b/src/resolvelib/resolvers.pyi index 0eb5b21..528a1a2 100644 --- a/src/resolvelib/resolvers.pyi +++ b/src/resolvelib/resolvers.pyi @@ -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]] diff --git a/tests/test_resolvers.py b/tests/test_resolvers.py index 01159e9..176108f 100644 --- a/tests/test_resolvers.py +++ b/tests/test_resolvers.py @@ -21,11 +21,11 @@ ResolutionImpossible, Resolver, ) -from resolvelib.resolvers import Resolution # type: ignore from resolvelib.resolvers import ( Criterion, RequirementInformation, RequirementsConflicted, + Resolution, ) @@ -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 = ( @@ -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: