diff --git a/src/poetry/repositories/http_repository.py b/src/poetry/repositories/http_repository.py index 6c000ac981f..54c7f0da1e9 100644 --- a/src/poetry/repositories/http_repository.py +++ b/src/poetry/repositories/http_repository.py @@ -166,7 +166,7 @@ def _get_info_from_metadata(self, link: Link) -> PackageInfo | None: response = self.session.get(link.metadata_url) if link.metadata_hashes and ( hash_name := get_highest_priority_hash_type( - set(link.metadata_hashes.keys()), f"{link.filename}.metadata" + link.metadata_hashes, f"{link.filename}.metadata" ) ): metadata_hash = getattr(hashlib, hash_name)( @@ -351,9 +351,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any] file_hash = self.calculate_sha256(link) if file_hash is None and ( - hash_type := get_highest_priority_hash_type( - set(link.hashes.keys()), link.filename - ) + hash_type := get_highest_priority_hash_type(link.hashes, link.filename) ): file_hash = f"{hash_type}:{link.hashes[hash_type]}" @@ -372,9 +370,7 @@ def _links_to_data(self, links: list[Link], data: PackageInfo) -> dict[str, Any] def calculate_sha256(self, link: Link) -> str | None: with self._cached_or_downloaded_file(link) as filepath: - hash_name = get_highest_priority_hash_type( - set(link.hashes.keys()), link.filename - ) + hash_name = get_highest_priority_hash_type(link.hashes, link.filename) known_hash = None with suppress(ValueError, AttributeError): # Handle ValueError here as well since under FIPS environments diff --git a/src/poetry/utils/cache.py b/src/poetry/utils/cache.py index 913fdb51beb..1f0f18ed5e5 100644 --- a/src/poetry/utils/cache.py +++ b/src/poetry/utils/cache.py @@ -198,9 +198,7 @@ def __init__(self, *, cache_dir: Path) -> None: def get_cache_directory_for_link(self, link: Link) -> Path: key_parts = {"url": link.url_without_fragment} - if hash_name := get_highest_priority_hash_type( - set(link.hashes.keys()), link.filename - ): + if hash_name := get_highest_priority_hash_type(link.hashes, link.filename): key_parts[hash_name] = link.hashes[hash_name] if link.subdirectory_fragment: diff --git a/src/poetry/utils/helpers.py b/src/poetry/utils/helpers.py index 81e9a281aee..4dcbab6e17c 100644 --- a/src/poetry/utils/helpers.py +++ b/src/poetry/utils/helpers.py @@ -28,6 +28,7 @@ if TYPE_CHECKING: from collections.abc import Callable + from collections.abc import Collection from collections.abc import Iterator from types import TracebackType @@ -332,7 +333,7 @@ def get_file_hash(path: Path, hash_name: str = "sha256") -> str: def get_highest_priority_hash_type( - hash_types: set[str], archive_name: str + hash_types: Collection[str], archive_name: str ) -> str | None: if not hash_types: return None