Skip to content

Commit 94f933f

Browse files
authored
markers: improve typing (no need for a dict, Mapping is sufficient for validate) (#729)
1 parent e0aca01 commit 94f933f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/poetry/core/version/markers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if TYPE_CHECKING:
2929
from collections.abc import Callable
3030
from collections.abc import Iterable
31+
from collections.abc import Mapping
3132

3233
from lark import Tree
3334

@@ -91,7 +92,7 @@ def is_empty(self) -> bool:
9192
return False
9293

9394
@abstractmethod
94-
def validate(self, environment: dict[str, Any] | None) -> bool:
95+
def validate(self, environment: Mapping[str, Any] | None) -> bool:
9596
raise NotImplementedError
9697

9798
@abstractmethod
@@ -132,7 +133,7 @@ def union(self, other: BaseMarker) -> BaseMarker:
132133
def is_any(self) -> bool:
133134
return True
134135

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

138139
def without_extras(self) -> BaseMarker:
@@ -173,7 +174,7 @@ def union(self, other: BaseMarker) -> BaseMarker:
173174
def is_empty(self) -> bool:
174175
return True
175176

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

179180
def without_extras(self) -> BaseMarker:
@@ -238,7 +239,7 @@ def constraint(self) -> SingleMarkerConstraint:
238239
def _key(self) -> tuple[object, ...]:
239240
return self._name, self._constraint
240241

241-
def validate(self, environment: dict[str, Any] | None) -> bool:
242+
def validate(self, environment: Mapping[str, Any] | None) -> bool:
242243
if environment is None:
243244
return True
244245

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

646647
return None
647648

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

651652
def without_extras(self) -> BaseMarker:
@@ -812,7 +813,7 @@ def intersect_simplify(self, other: BaseMarker) -> BaseMarker | None:
812813

813814
return None
814815

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

818819
def without_extras(self) -> BaseMarker:

0 commit comments

Comments
 (0)