From 96c132698cebc7c66934eb0127f50848b4ca2db4 Mon Sep 17 00:00:00 2001 From: Stephan Finkensieper Date: Fri, 26 Apr 2024 15:30:13 +0000 Subject: [PATCH] Add type hints for poetry dependency with hash --- conda_lock/pypi_solver.py | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/conda_lock/pypi_solver.py b/conda_lock/pypi_solver.py index 07d930b5f..7666ad1e0 100644 --- a/conda_lock/pypi_solver.py +++ b/conda_lock/pypi_solver.py @@ -4,7 +4,7 @@ from pathlib import Path from posixpath import expandvars -from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Union +from typing import TYPE_CHECKING, Dict, FrozenSet, List, Literal, Optional, Tuple, Union from urllib.parse import urldefrag, urlsplit, urlunsplit from clikit.api.io.flags import VERY_VERBOSE @@ -12,6 +12,7 @@ from packaging.tags import compatible_tags, cpython_tags, mac_platforms from packaging.version import Version +from conda_lock._vendor.poetry.core.semver import VersionConstraint from conda_lock.interfaces.vendored_poetry import ( Chooser, Env, @@ -280,9 +281,33 @@ def parse_pip_requirement(requirement: str) -> Optional[Dict[str, str]]: class PoetryDependencyWithHash(PoetryDependency): - def __init__(self, *args, hash: Optional[str] = None, **kwargs) -> None: + def __init__( + self, + name, # type: str + constraint, # type: Union[str, VersionConstraint] + optional=False, # type: bool + category="main", # type: str + allows_prereleases=False, # type: bool + extras=None, # type: Optional[Union[List[str], FrozenSet[str]]] + source_type=None, # type: Optional[str] + source_url=None, # type: Optional[str] + source_reference=None, # type: Optional[str] + source_resolved_reference=None, # type: Optional[str] + hash: Optional[str] = None, + ) -> None: + super().__init__( + name, + constraint, + optional=optional, + category=category, + allows_prereleases=allows_prereleases, + extras=extras, # type: ignore # upstream type hint is wrong + source_type=source_type, + source_url=source_url, + source_reference=source_reference, + source_resolved_reference=source_resolved_reference, + ) self.hash = hash - super().__init__(*args, **kwargs) def get_hash_model(self) -> Optional[HashModel]: if self.hash: