From 94f933f50ade83cb7f13a2c521477aa4b8a0b1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Thu, 9 May 2024 11:31:29 +0200 Subject: [PATCH] markers: improve typing (no need for a dict, Mapping is sufficient for validate) (#729) --- src/poetry/core/version/markers.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/poetry/core/version/markers.py b/src/poetry/core/version/markers.py index 9f26fb152..bb2f23006 100644 --- a/src/poetry/core/version/markers.py +++ b/src/poetry/core/version/markers.py @@ -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 @@ -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 @@ -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: @@ -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: @@ -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 @@ -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: @@ -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: