Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mypy: adapt type hints to change in poetry-core#442 #6163

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 55 additions & 46 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ generate-setup-file = false
[tool.poetry.dependencies]
python = "^3.7"

poetry-core = "^1.1.0b3"
poetry-core = "^1.1.0rc1"
poetry-plugin-export = "^1.0.6"
cachecontrol = { version = "^0.12.9", extras = ["filecache"] }
cachy = "^0.3.0"
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core.packages.package import Package
from tomlkit.items import InlineTable

Expand Down Expand Up @@ -238,7 +239,7 @@ def handle(self) -> int:
return 0

def _generate_choice_list(
self, matches: list[Package], canonicalized_name: str
self, matches: list[Package], canonicalized_name: NormalizedName
) -> list[str]:
choices = []
matches_names = [p.name for p in matches]
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/console/commands/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

if TYPE_CHECKING:
from cleo.io.io import IO
from packaging.utils import NormalizedName
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.project_package import ProjectPackage
Expand Down Expand Up @@ -423,7 +424,7 @@ def _display_tree(
io: IO,
dependency: Dependency,
installed_packages: list[Package],
packages_in_tree: list[str],
packages_in_tree: list[NormalizedName],
previous_tree_bar: str = "├",
level: int = 1,
) -> None:
Expand Down
1 change: 1 addition & 0 deletions src/poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def _get_extra_packages(self, repo: Repository) -> list[str]:

Maybe we just let the solver handle it?
"""
extras: dict[str, list[str]]
if self._update:
extras = {k: [d.name for d in v] for k, v in self._package.extras.items()}
else:
Expand Down
7 changes: 5 additions & 2 deletions src/poetry/repositories/legacy_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core.packages.utils.link import Link
from poetry.core.semver.version_constraint import VersionConstraint

Expand Down Expand Up @@ -66,13 +67,15 @@ def find_links_for_package(self, package: Package) -> list[Link]:

return list(page.links_for_version(package.name, package.version))

def _find_packages(self, name: str, constraint: VersionConstraint) -> list[Package]:
def _find_packages(
self, name: NormalizedName, constraint: VersionConstraint
) -> list[Package]:
"""
Find packages on the remote server.
"""
versions: list[Version]

key = name
key: str = name
if not constraint.is_any():
key = f"{key}:{constraint!s}"

Expand Down
9 changes: 6 additions & 3 deletions src/poetry/repositories/pypi_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core.semver.version_constraint import VersionConstraint


Expand Down Expand Up @@ -90,7 +91,7 @@ def search(self, query: str) -> list[Package]:

return results

def get_package_info(self, name: str) -> dict[str, Any]:
def get_package_info(self, name: NormalizedName) -> dict[str, Any]:
"""
Return the package information given its name.

Expand All @@ -105,7 +106,9 @@ def get_package_info(self, name: str) -> dict[str, Any]:
)
return package_info

def _find_packages(self, name: str, constraint: VersionConstraint) -> list[Package]:
def _find_packages(
self, name: NormalizedName, constraint: VersionConstraint
) -> list[Package]:
"""
Find packages on the remote server.
"""
Expand Down Expand Up @@ -145,7 +148,7 @@ def _find_packages(self, name: str, constraint: VersionConstraint) -> list[Packa

return packages

def _get_package_info(self, name: str) -> dict[str, Any]:
def _get_package_info(self, name: NormalizedName) -> dict[str, Any]:
data = self._get(f"pypi/{name}/json")
if data is None:
raise PackageNotFound(f"Package [{name}] not found.")
Expand Down
5 changes: 4 additions & 1 deletion src/poetry/repositories/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


if TYPE_CHECKING:
from packaging.utils import NormalizedName
from poetry.core.packages.dependency import Dependency
from poetry.core.packages.package import Package
from poetry.core.packages.utils.link import Link
Expand Down Expand Up @@ -112,7 +113,9 @@ def _get_constraints_from_dependency(

return constraint, allow_prereleases

def _find_packages(self, name: str, constraint: VersionConstraint) -> list[Package]:
def _find_packages(
self, name: NormalizedName, constraint: VersionConstraint
) -> list[Package]:
return [
package
for package in self._packages
Expand Down
5 changes: 3 additions & 2 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,9 @@ def activate(self, python: str, io: IO) -> Env:

def deactivate(self, io: IO) -> None:
venv_path = self._poetry.config.virtualenvs_path
name = self._poetry.package.name
name = self.generate_env_name(name, str(self._poetry.file.parent))
name = self.generate_env_name(
self._poetry.package.name, str(self._poetry.file.parent)
)

envs_file = TOMLFile(venv_path / self.ENVS_FILE)
if envs_file.exists():
Expand Down
7 changes: 5 additions & 2 deletions src/poetry/utils/extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from collections.abc import Sequence
from typing import Mapping

from packaging.utils import NormalizedName
from poetry.core.packages.package import Package


Expand Down Expand Up @@ -43,13 +44,15 @@ def get_extra_package_names(
# keep record of packages seen during recursion in order to avoid recursion error
seen_package_names = set()

def _extra_packages(package_names: Iterable[str]) -> Iterator[str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

   def _extra_packages(
        package_names: Iterable[NormalizedName],
    ) -> Iterator[NormalizedName]:

and remove the redundant canonicalize_name() at line 52

def _extra_packages(
package_names: Iterable[NormalizedName],
) -> Iterator[NormalizedName]:
"""Recursively find dependencies for packages names"""
# for each extra package name
for package_name in package_names:
# Find the actual Package object. A missing key indicates an implicit
# dependency (like setuptools), which should be ignored
package = packages_by_name.get(canonicalize_name(package_name))
package = packages_by_name.get(package_name)
if package:
if package.name not in seen_package_names:
seen_package_names.add(package.name)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/test_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_get_extra_package_names(
extras: dict[str, list[str]],
extra_names: list[str],
expected_extra_package_names: list[str],
):
) -> None:
assert (
list(get_extra_package_names(packages, extras, extra_names))
== expected_extra_package_names
Expand Down