Commit a00eb5c3 by Branch Vincent Committed by Bjorn Neergaard

chore(console): remove type errors

parent 839f7c40
...@@ -116,7 +116,6 @@ enable_error_code = ["ignore-without-code"] ...@@ -116,7 +116,6 @@ enable_error_code = ["ignore-without-code"]
[[tool.mypy.overrides]] [[tool.mypy.overrides]]
module = [ module = [
'poetry.console.commands.init',
'poetry.inspection.info', 'poetry.inspection.info',
'poetry.installation.chef', 'poetry.installation.chef',
'poetry.installation.chooser', 'poetry.installation.chooser',
......
...@@ -5,7 +5,9 @@ import sys ...@@ -5,7 +5,9 @@ import sys
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
from typing import Dict
from typing import Mapping from typing import Mapping
from typing import Union
from cleo.helpers import option from cleo.helpers import option
from tomlkit import inline_table from tomlkit import inline_table
...@@ -22,6 +24,8 @@ if TYPE_CHECKING: ...@@ -22,6 +24,8 @@ if TYPE_CHECKING:
from poetry.repositories import Pool from poetry.repositories import Pool
Requirements = Dict[str, Union[str, Mapping[str, Any]]]
class InitCommand(Command): class InitCommand(Command):
name = "init" name = "init"
...@@ -162,7 +166,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the ...@@ -162,7 +166,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
if self.io.is_interactive(): if self.io.is_interactive():
self.line("") self.line("")
requirements = {} requirements: Requirements = {}
if self.option("dependency"): if self.option("dependency"):
requirements = self._format_requirements( requirements = self._format_requirements(
self._determine_requirements(self.option("dependency")) self._determine_requirements(self.option("dependency"))
...@@ -192,7 +196,7 @@ You can specify a package in the following forms: ...@@ -192,7 +196,7 @@ You can specify a package in the following forms:
if self.io.is_interactive(): if self.io.is_interactive():
self.line("") self.line("")
dev_requirements: dict[str, str] = {} dev_requirements: Requirements = {}
if self.option("dev-dependency"): if self.option("dev-dependency"):
dev_requirements = self._format_requirements( dev_requirements = self._format_requirements(
self._determine_requirements(self.option("dev-dependency")) self._determine_requirements(self.option("dev-dependency"))
...@@ -264,9 +268,9 @@ You can specify a package in the following forms: ...@@ -264,9 +268,9 @@ You can specify a package in the following forms:
requires: list[str], requires: list[str],
allow_prereleases: bool = False, allow_prereleases: bool = False,
source: str | None = None, source: str | None = None,
) -> list[dict[str, str | list[str]]]: ) -> list[dict[str, Any]]:
if not requires: if not requires:
requires = [] result = []
package = self.ask( package = self.ask(
"Search for package to add (or leave blank to continue):" "Search for package to add (or leave blank to continue):"
...@@ -280,7 +284,7 @@ You can specify a package in the following forms: ...@@ -280,7 +284,7 @@ You can specify a package in the following forms:
or "version" in constraint or "version" in constraint
): ):
self.line(f"Adding <info>{package}</info>") self.line(f"Adding <info>{package}</info>")
requires.append(constraint) result.append(constraint)
package = self.ask("\nAdd a package:") package = self.ask("\nAdd a package:")
continue continue
...@@ -337,16 +341,15 @@ You can specify a package in the following forms: ...@@ -337,16 +341,15 @@ You can specify a package in the following forms:
constraint["version"] = package_constraint constraint["version"] = package_constraint
if package is not False: if package is not False:
requires.append(constraint) result.append(constraint)
if self.io.is_interactive(): if self.io.is_interactive():
package = self.ask("\nAdd a package:") package = self.ask("\nAdd a package:")
return requires return result
requires = self._parse_requirements(requires)
result = [] result = []
for requirement in requires: for requirement in self._parse_requirements(requires):
if "git" in requirement or "url" in requirement or "path" in requirement: if "git" in requirement or "url" in requirement or "path" in requirement:
result.append(requirement) result.append(requirement)
continue continue
...@@ -414,10 +417,8 @@ You can specify a package in the following forms: ...@@ -414,10 +417,8 @@ You can specify a package in the following forms:
for requirement in requirements for requirement in requirements
] ]
def _format_requirements( def _format_requirements(self, requirements: list[dict[str, str]]) -> Requirements:
self, requirements: list[dict[str, str]] requires: Requirements = {}
) -> Mapping[str, str | Mapping[str, str]]:
requires = {}
for requirement in requirements: for requirement in requirements:
name = requirement.pop("name") name = requirement.pop("name")
constraint: str | InlineTable constraint: str | InlineTable
......
...@@ -3,6 +3,7 @@ from __future__ import annotations ...@@ -3,6 +3,7 @@ from __future__ import annotations
from pathlib import Path from pathlib import Path
from typing import TYPE_CHECKING from typing import TYPE_CHECKING
from typing import Any from typing import Any
from typing import Mapping
from tomlkit import dumps from tomlkit import dumps
from tomlkit import inline_table from tomlkit import inline_table
...@@ -50,8 +51,8 @@ class Layout: ...@@ -50,8 +51,8 @@ class Layout:
author: str | None = None, author: str | None = None,
license: str | None = None, license: str | None = None,
python: str = "*", python: str = "*",
dependencies: dict[str, str] | None = None, dependencies: dict[str, str | Mapping[str, Any]] | None = None,
dev_dependencies: dict[str, str] | None = None, dev_dependencies: dict[str, str | Mapping[str, Any]] | None = None,
) -> None: ) -> None:
self._project = canonicalize_name(project).replace(".", "-") self._project = canonicalize_name(project).replace(".", "-")
self._package_path_relative = Path( self._package_path_relative = Path(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment