Skip to content

Commit

Permalink
Merge pull request #166 from notatallshaw/guard-type-hinting
Browse files Browse the repository at this point in the history
Guard type hinting via ruff
  • Loading branch information
frostming authored Aug 2, 2024
2 parents 4cb0a23 + 1e24847 commit b45601d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 2 additions & 0 deletions news/166.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Enable automatic TYPE_CHECK guarding for imports only used for type hinting
via ruff rules TCH and FA
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ src = ["src"]
line-length = 88

[tool.ruff.lint]
select = ["C","E","F","W","B","RUF","PLE","PLW","I"]
select = ["C","E","F","W","B","RUF","PLE","PLW","I","TCH","FA"]
ignore = ["PLW2901"]
exclude = [
".git",
Expand Down
6 changes: 3 additions & 3 deletions src/resolvelib/resolvers/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import collections
from typing import TYPE_CHECKING, Any, Generic, Iterable, Mapping, NamedTuple

from ..providers import AbstractProvider
from ..reporters import BaseReporter
from ..structs import CT, KT, RT, DirectedGraph
from .criterion import Criterion

if TYPE_CHECKING:
from ..providers import AbstractProvider
from ..reporters import BaseReporter
from .criterion import Criterion

class Result(NamedTuple, Generic[RT, CT, KT]):
mapping: Mapping[KT, CT]
Expand Down
6 changes: 4 additions & 2 deletions src/resolvelib/resolvers/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from __future__ import annotations

from typing import Collection, Generic
from typing import TYPE_CHECKING, Collection, Generic

from ..structs import CT, RT, RequirementInformation
from .criterion import Criterion

if TYPE_CHECKING:
from .criterion import Criterion


class ResolverException(Exception):
Expand Down
5 changes: 2 additions & 3 deletions src/resolvelib/resolvers/resolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import operator
from typing import TYPE_CHECKING, Collection, Generic, Iterable, Mapping

from ..providers import AbstractProvider
from ..reporters import BaseReporter
from ..structs import (
CT,
KT,
Expand All @@ -29,7 +27,8 @@
)

if TYPE_CHECKING:
from ..providers import Preference
from ..providers import AbstractProvider, Preference
from ..reporters import BaseReporter


def _build_result(state: State[RT, CT, KT]) -> Result[RT, CT, KT]:
Expand Down
7 changes: 5 additions & 2 deletions tests/test_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
InconsistentCandidate,
ResolutionImpossible,
)
from resolvelib.resolvers import Resolution, Resolver
from resolvelib.resolvers import (
RequirementsConflicted,
Resolution,
Resolver,
)

if TYPE_CHECKING:
from typing import Iterable, Mapping

from resolvelib.resolvers import (
Criterion,
RequirementInformation,
RequirementsConflicted,
)


Expand Down

0 comments on commit b45601d

Please sign in to comment.