Skip to content

Commit

Permalink
markers: improve typing (no need for a dict, Mapping is sufficient fo…
Browse files Browse the repository at this point in the history
…r validate) (#729)
  • Loading branch information
radoering committed May 9, 2024
1 parent e0aca01 commit 94f933f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/poetry/core/version/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Iterable
from collections.abc import Mapping

from lark import Tree

Expand Down Expand Up @@ -91,7 +92,7 @@ def is_empty(self) -> bool:
return False

@abstractmethod
def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
raise NotImplementedError

@abstractmethod
Expand Down Expand Up @@ -132,7 +133,7 @@ def union(self, other: BaseMarker) -> BaseMarker:
def is_any(self) -> bool:
return True

def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
return True

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -173,7 +174,7 @@ def union(self, other: BaseMarker) -> BaseMarker:
def is_empty(self) -> bool:
return True

def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
return False

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -238,7 +239,7 @@ def constraint(self) -> SingleMarkerConstraint:
def _key(self) -> tuple[object, ...]:
return self._name, self._constraint

def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
if environment is None:
return True

Expand Down Expand Up @@ -645,7 +646,7 @@ def union_simplify(self, other: BaseMarker) -> BaseMarker | None:

return None

def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
return all(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down Expand Up @@ -812,7 +813,7 @@ def intersect_simplify(self, other: BaseMarker) -> BaseMarker | None:

return None

def validate(self, environment: dict[str, Any] | None) -> bool:
def validate(self, environment: Mapping[str, Any] | None) -> bool:
return any(m.validate(environment) for m in self._markers)

def without_extras(self) -> BaseMarker:
Expand Down

0 comments on commit 94f933f

Please sign in to comment.