diff --git a/pyproject.toml b/pyproject.toml index 92cfa77cc1d..4d43988ad18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -136,8 +136,6 @@ known-first-party = ["poetry"] known-third-party = ["poetry.core"] required-imports = ["from __future__ import annotations"] -[tool.ruff.lint.per-file-ignores] -"src/poetry/console/*" = ["RUF012"] # Can't annotate properly until new version of Cleo [tool.mypy] files = "src, tests" diff --git a/src/poetry/console/commands/add.py b/src/poetry/console/commands/add.py index a5fcbc7a2ca..6f4e4b06314 100644 --- a/src/poetry/console/commands/add.py +++ b/src/poetry/console/commands/add.py @@ -2,7 +2,9 @@ import contextlib +from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -14,12 +16,19 @@ from poetry.console.commands.installer_command import InstallerCommand +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class AddCommand(InstallerCommand, InitCommand): name = "add" description = "Adds a new dependency to pyproject.toml." - arguments = [argument("name", "The packages to add.", multiple=True)] - options = [ + arguments: ClassVar[list[Argument]] = [ + argument("name", "The packages to add.", multiple=True) + ] + options: ClassVar[list[Option]] = [ option( "group", "-G", @@ -95,7 +104,10 @@ class AddCommand(InstallerCommand, InitCommand): {examples} """ - loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"] + loggers: ClassVar[list[str]] = [ + "poetry.repositories.pypi_repository", + "poetry.inspection.info", + ] def handle(self) -> int: from poetry.core.constraints.version import parse_constraint diff --git a/src/poetry/console/commands/build.py b/src/poetry/console/commands/build.py index 41018ef4d67..3b2df69de4e 100644 --- a/src/poetry/console/commands/build.py +++ b/src/poetry/console/commands/build.py @@ -1,6 +1,8 @@ from __future__ import annotations from pathlib import Path +from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import option @@ -9,11 +11,15 @@ from poetry.utils.helpers import remove_directory +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class BuildCommand(EnvCommand): name = "build" description = "Builds a package, as a tarball and a wheel by default." - options = [ + options: ClassVar[list[Option]] = [ option("format", "f", "Limit the format to either sdist or wheel.", flag=False), option( "clean", @@ -35,7 +41,7 @@ class BuildCommand(EnvCommand): ), ] - loggers = [ + loggers: ClassVar[list[str]] = [ "poetry.core.masonry.builders.builder", "poetry.core.masonry.builders.sdist", "poetry.core.masonry.builders.wheel", diff --git a/src/poetry/console/commands/cache/clear.py b/src/poetry/console/commands/cache/clear.py index 9896efd43d1..f3057f3fd64 100644 --- a/src/poetry/console/commands/cache/clear.py +++ b/src/poetry/console/commands/cache/clear.py @@ -2,6 +2,9 @@ import os +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from cleo.helpers import option from packaging.utils import canonicalize_name @@ -11,12 +14,21 @@ from poetry.utils.cache import FileCache +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class CacheClearCommand(Command): name = "cache clear" description = "Clears a Poetry cache by name." - arguments = [argument("cache", description="The name of the cache to clear.")] - options = [option("all", description="Clear all entries in the cache.")] + arguments: ClassVar[list[Argument]] = [ + argument("cache", description="The name of the cache to clear.") + ] + options: ClassVar[list[Option]] = [ + option("all", description="Clear all entries in the cache.") + ] def handle(self) -> int: cache = self.argument("cache") diff --git a/src/poetry/console/commands/check.py b/src/poetry/console/commands/check.py index 6f53685309d..ba533f992ee 100644 --- a/src/poetry/console/commands/check.py +++ b/src/poetry/console/commands/check.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from cleo.helpers import option @@ -11,6 +12,8 @@ if TYPE_CHECKING: from pathlib import Path + from cleo.io.inputs.option import Option + class CheckCommand(Command): name = "check" @@ -19,7 +22,7 @@ class CheckCommand(Command): " consistency with the poetry.lock file." ) - options = [ + options: ClassVar[list[Option]] = [ option( "lock", None, diff --git a/src/poetry/console/commands/command.py b/src/poetry/console/commands/command.py index 2aba4e6be24..ff3b95b281b 100644 --- a/src/poetry/console/commands/command.py +++ b/src/poetry/console/commands/command.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from cleo.commands.command import Command as BaseCommand from cleo.exceptions import CleoValueError @@ -13,7 +14,7 @@ class Command(BaseCommand): - loggers: list[str] = [] + loggers: ClassVar[list[str]] = [] _poetry: Poetry | None = None diff --git a/src/poetry/console/commands/config.py b/src/poetry/console/commands/config.py index 3d0162e12c0..17296ec24ea 100644 --- a/src/poetry/console/commands/config.py +++ b/src/poetry/console/commands/config.py @@ -6,6 +6,7 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from typing import cast from cleo.helpers import argument @@ -19,6 +20,9 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + from poetry.config.config_source import ConfigSource @@ -26,12 +30,12 @@ class ConfigCommand(Command): name = "config" description = "Manages configuration settings." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument("key", "Setting key.", optional=True), argument("value", "Setting value.", optional=True, multiple=True), ] - options = [ + options: ClassVar[list[Option]] = [ option("list", None, "List configuration settings."), option("unset", None, "Unset configuration setting."), option("local", None, "Set/Get from the project's local configuration."), @@ -48,7 +52,7 @@ class ConfigCommand(Command): poetry config --unset repo.foo""" - LIST_PROHIBITED_SETTINGS = {"http-basic", "pypi-token"} + LIST_PROHIBITED_SETTINGS: ClassVar[set[str]] = {"http-basic", "pypi-token"} @property def unique_config_values(self) -> dict[str, tuple[Any, Any]]: diff --git a/src/poetry/console/commands/debug/resolve.py b/src/poetry/console/commands/debug/resolve.py index ec168f6adf8..8bf36668697 100644 --- a/src/poetry/console/commands/debug/resolve.py +++ b/src/poetry/console/commands/debug/resolve.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -11,6 +12,8 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option from cleo.ui.table import Rows @@ -18,10 +21,10 @@ class DebugResolveCommand(InitCommand): name = "debug resolve" description = "Debugs dependency resolution." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument("package", "The packages to resolve.", optional=True, multiple=True) ] - options = [ + options: ClassVar[list[Option]] = [ option( "extras", "E", @@ -34,7 +37,10 @@ class DebugResolveCommand(InitCommand): option("install", None, "Show what would be installed for the current system."), ] - loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"] + loggers: ClassVar[list[str]] = [ + "poetry.repositories.pypi_repository", + "poetry.inspection.info", + ] def handle(self) -> int: from cleo.io.null_io import NullIO diff --git a/src/poetry/console/commands/env/info.py b/src/poetry/console/commands/env/info.py index cb8152a8331..0e4a71763fe 100644 --- a/src/poetry/console/commands/env/info.py +++ b/src/poetry/console/commands/env/info.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import option @@ -8,6 +9,8 @@ if TYPE_CHECKING: + from cleo.io.inputs.option import Option + from poetry.utils.env import Env @@ -15,7 +18,7 @@ class EnvInfoCommand(Command): name = "env info" description = "Displays information about the current environment." - options = [ + options: ClassVar[list[Option]] = [ option("path", "p", "Only display the environment's path."), option( "executable", "e", "Only display the environment's python executable path." diff --git a/src/poetry/console/commands/env/list.py b/src/poetry/console/commands/env/list.py index e8c89e8bea7..27ba60c5d09 100644 --- a/src/poetry/console/commands/env/list.py +++ b/src/poetry/console/commands/env/list.py @@ -1,15 +1,24 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import option from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class EnvListCommand(Command): name = "env list" description = "Lists all virtualenvs associated with the current project." - options = [option("full-path", None, "Output the full paths of the virtualenvs.")] + options: ClassVar[list[Option]] = [ + option("full-path", None, "Output the full paths of the virtualenvs.") + ] def handle(self) -> int: from poetry.utils.env import EnvManager diff --git a/src/poetry/console/commands/env/remove.py b/src/poetry/console/commands/env/remove.py index 4325f045b39..4371ec4f84b 100644 --- a/src/poetry/console/commands/env/remove.py +++ b/src/poetry/console/commands/env/remove.py @@ -1,16 +1,24 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from cleo.helpers import option from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class EnvRemoveCommand(Command): name = "env remove" description = "Remove virtual environments associated with the project." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "python", "The python executables associated with, or names of the virtual" @@ -19,7 +27,7 @@ class EnvRemoveCommand(Command): multiple=True, ) ] - options = [ + options: ClassVar[list[Option]] = [ option( "all", description=( diff --git a/src/poetry/console/commands/env/use.py b/src/poetry/console/commands/env/use.py index c48312d9e4c..d07a5f63cba 100644 --- a/src/poetry/console/commands/env/use.py +++ b/src/poetry/console/commands/env/use.py @@ -1,15 +1,24 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + + class EnvUseCommand(Command): name = "env use" description = "Activates or creates a new virtualenv for the current project." - arguments = [argument("python", "The python executable to use.")] + arguments: ClassVar[list[Argument]] = [ + argument("python", "The python executable to use.") + ] def handle(self) -> int: from poetry.utils.env import EnvManager diff --git a/src/poetry/console/commands/init.py b/src/poetry/console/commands/init.py index fe708c98ab4..670fa4cb09e 100644 --- a/src/poetry/console/commands/init.py +++ b/src/poetry/console/commands/init.py @@ -3,6 +3,7 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from typing import Dict from typing import Mapping from typing import Union @@ -17,6 +18,7 @@ if TYPE_CHECKING: + from cleo.io.inputs.option import Option from packaging.utils import NormalizedName from poetry.core.packages.package import Package from tomlkit.items import InlineTable @@ -32,7 +34,7 @@ class InitCommand(Command): "Creates a basic pyproject.toml file in the current directory." ) - options = [ + options: ClassVar[list[Option]] = [ option("name", None, "Name of the package.", flag=False), option("description", None, "Description of the package.", flag=False), option("author", None, "Author name of the package.", flag=False), diff --git a/src/poetry/console/commands/install.py b/src/poetry/console/commands/install.py index 55037d41d77..7234a1cebcb 100644 --- a/src/poetry/console/commands/install.py +++ b/src/poetry/console/commands/install.py @@ -1,15 +1,22 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import option from poetry.console.commands.installer_command import InstallerCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class InstallCommand(InstallerCommand): name = "install" description = "Installs the project dependencies." - options = [ + options: ClassVar[list[Option]] = [ *InstallerCommand._group_dependency_options(), option( "no-dev", @@ -82,7 +89,10 @@ class InstallCommand(InstallerCommand): you can set the "package-mode" to false in your pyproject.toml file. """ - _loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"] + _loggers: ClassVar[list[str]] = [ + "poetry.repositories.pypi_repository", + "poetry.inspection.info", + ] @property def activated_groups(self) -> set[str]: diff --git a/src/poetry/console/commands/lock.py b/src/poetry/console/commands/lock.py index fd8eda77936..c64f1dfd2ad 100644 --- a/src/poetry/console/commands/lock.py +++ b/src/poetry/console/commands/lock.py @@ -1,15 +1,22 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import option from poetry.console.commands.installer_command import InstallerCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class LockCommand(InstallerCommand): name = "lock" description = "Locks the project dependencies." - options = [ + options: ClassVar[list[Option]] = [ option( "no-update", None, "Do not update locked versions, only refresh lock file." ), @@ -31,7 +38,7 @@ class LockCommand(InstallerCommand): poetry lock """ - loggers = ["poetry.repositories.pypi_repository"] + loggers: ClassVar[list[str]] = ["poetry.repositories.pypi_repository"] def handle(self) -> int: if self.option("check"): diff --git a/src/poetry/console/commands/new.py b/src/poetry/console/commands/new.py index 5f896cf80e8..fd32fa6137f 100644 --- a/src/poetry/console/commands/new.py +++ b/src/poetry/console/commands/new.py @@ -1,6 +1,8 @@ from __future__ import annotations from contextlib import suppress +from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -8,12 +10,19 @@ from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class NewCommand(Command): name = "new" description = "Creates a new Python project at ." - arguments = [argument("path", "The path to create the project at.")] - options = [ + arguments: ClassVar[list[Argument]] = [ + argument("path", "The path to create the project at.") + ] + options: ClassVar[list[Option]] = [ option("name", None, "Set the resulting package name.", flag=False), option("src", None, "Use the src layout for the project."), option( diff --git a/src/poetry/console/commands/publish.py b/src/poetry/console/commands/publish.py index 2671c7a11d1..a9395620cb9 100644 --- a/src/poetry/console/commands/publish.py +++ b/src/poetry/console/commands/publish.py @@ -1,17 +1,23 @@ from __future__ import annotations from pathlib import Path +from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import option from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class PublishCommand(Command): name = "publish" description = "Publishes a package to a remote repository." - options = [ + options: ClassVar[list[Option]] = [ option( "repository", "r", "The repository to publish the package to.", flag=False ), @@ -51,7 +57,7 @@ class PublishCommand(Command): the config command. """ - loggers = ["poetry.publishing.publisher"] + loggers: ClassVar[list[str]] = ["poetry.publishing.publisher"] def handle(self) -> int: from poetry.publishing.publisher import Publisher diff --git a/src/poetry/console/commands/remove.py b/src/poetry/console/commands/remove.py index d4315e80bf8..620bc21e510 100644 --- a/src/poetry/console/commands/remove.py +++ b/src/poetry/console/commands/remove.py @@ -1,6 +1,8 @@ from __future__ import annotations +from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -11,12 +13,19 @@ from poetry.console.commands.installer_command import InstallerCommand +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class RemoveCommand(InstallerCommand): name = "remove" description = "Removes a package from the project dependencies." - arguments = [argument("packages", "The packages to remove.", multiple=True)] - options = [ + arguments: ClassVar[list[Argument]] = [ + argument("packages", "The packages to remove.", multiple=True) + ] + options: ClassVar[list[Option]] = [ option("group", "G", "The group to remove the dependency from.", flag=False), option( "dev", @@ -39,7 +48,10 @@ class RemoveCommand(InstallerCommand): poetry remove""" - loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"] + loggers: ClassVar[list[str]] = [ + "poetry.repositories.pypi_repository", + "poetry.inspection.info", + ] def handle(self) -> int: packages = self.argument("packages") diff --git a/src/poetry/console/commands/run.py b/src/poetry/console/commands/run.py index 98736280bf2..b2bfc67cd95 100644 --- a/src/poetry/console/commands/run.py +++ b/src/poetry/console/commands/run.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import argument @@ -9,6 +10,7 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument from poetry.core.masonry.utils.module import Module @@ -16,7 +18,7 @@ class RunCommand(EnvCommand): name = "run" description = "Runs a command in the appropriate environment." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument("args", "The command and arguments/options to run.", multiple=True) ] diff --git a/src/poetry/console/commands/search.py b/src/poetry/console/commands/search.py index 429f686898a..5705b06b493 100644 --- a/src/poetry/console/commands/search.py +++ b/src/poetry/console/commands/search.py @@ -1,15 +1,24 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + + class SearchCommand(Command): name = "search" description = "Searches for packages on remote repositories." - arguments = [argument("tokens", "The tokens to search for.", multiple=True)] + arguments: ClassVar[list[Argument]] = [ + argument("tokens", "The tokens to search for.", multiple=True) + ] def handle(self) -> int: from poetry.repositories.pypi_repository import PyPiRepository diff --git a/src/poetry/console/commands/self/add.py b/src/poetry/console/commands/self/add.py index b8c5657eb85..946e13d474c 100644 --- a/src/poetry/console/commands/self/add.py +++ b/src/poetry/console/commands/self/add.py @@ -1,5 +1,8 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from poetry.core.constraints.version import Version from poetry.__version__ import __version__ @@ -7,10 +10,14 @@ from poetry.console.commands.self.self_command import SelfCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class SelfAddCommand(SelfCommand, AddCommand): name = "self add" description = "Add additional packages to Poetry's runtime environment." - options = [ + options: ClassVar[list[Option]] = [ o for o in AddCommand.options if o.name in {"editable", "extras", "source", "dry-run", "allow-prereleases"} diff --git a/src/poetry/console/commands/self/install.py b/src/poetry/console/commands/self/install.py index ec70f734644..c0870b2280e 100644 --- a/src/poetry/console/commands/self/install.py +++ b/src/poetry/console/commands/self/install.py @@ -1,17 +1,26 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from poetry.core.packages.dependency_group import MAIN_GROUP from poetry.console.commands.install import InstallCommand from poetry.console.commands.self.self_command import SelfCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class SelfInstallCommand(SelfCommand, InstallCommand): name = "self install" description = ( "Install locked packages (incl. addons) required by this Poetry installation." ) - options = [o for o in InstallCommand.options if o.name in {"sync", "dry-run"}] + options: ClassVar[list[Option]] = [ + o for o in InstallCommand.options if o.name in {"sync", "dry-run"} + ] help = f"""\ The self install command ensures all additional packages specified are \ installed in the current runtime environment. diff --git a/src/poetry/console/commands/self/remove.py b/src/poetry/console/commands/self/remove.py index 59f1d2fa614..fc890b18c2b 100644 --- a/src/poetry/console/commands/self/remove.py +++ b/src/poetry/console/commands/self/remove.py @@ -1,13 +1,22 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from poetry.console.commands.remove import RemoveCommand from poetry.console.commands.self.self_command import SelfCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class SelfRemoveCommand(SelfCommand, RemoveCommand): name = "self remove" description = "Remove additional packages from Poetry's runtime environment." - options = [o for o in RemoveCommand.options if o.name in {"dry-run"}] + options: ClassVar[list[Option]] = [ + o for o in RemoveCommand.options if o.name in {"dry-run"} + ] help = f"""\ The self remove command removes additional package's to Poetry's runtime \ environment. diff --git a/src/poetry/console/commands/self/show/__init__.py b/src/poetry/console/commands/self/show/__init__.py index 7212d69c7e1..8f4060ad2a3 100644 --- a/src/poetry/console/commands/self/show/__init__.py +++ b/src/poetry/console/commands/self/show/__init__.py @@ -1,14 +1,21 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import option from poetry.console.commands.self.self_command import SelfCommand from poetry.console.commands.show import ShowCommand +if TYPE_CHECKING: + from cleo.io.inputs.option import Option + + class SelfShowCommand(SelfCommand, ShowCommand): name = "self show" - options = [ + options: ClassVar[list[Option]] = [ option("addons", None, "List only add-on packages installed."), *[o for o in ShowCommand.options if o.name in {"tree", "latest", "outdated"}], ] diff --git a/src/poetry/console/commands/self/update.py b/src/poetry/console/commands/self/update.py index f42a3d477d8..24e1f7326e9 100644 --- a/src/poetry/console/commands/self/update.py +++ b/src/poetry/console/commands/self/update.py @@ -1,5 +1,8 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from cleo.helpers import option from cleo.io.inputs.string_input import StringInput @@ -9,16 +12,21 @@ from poetry.console.commands.self.self_command import SelfCommand +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class SelfUpdateCommand(SelfCommand): name = "self update" description = "Updates Poetry to the latest version." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "version", "The version to update to.", optional=True, default="latest" ) ] - options = [ + options: ClassVar[list[Option]] = [ option("preview", None, "Allow the installation of pre-release versions."), option( "dry-run", diff --git a/src/poetry/console/commands/show.py b/src/poetry/console/commands/show.py index 1208ca4c3c2..6bcd7eca7fb 100644 --- a/src/poetry/console/commands/show.py +++ b/src/poetry/console/commands/show.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -11,6 +12,8 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option from cleo.io.io import IO from cleo.ui.table import Rows from packaging.utils import NormalizedName @@ -36,8 +39,10 @@ class ShowCommand(GroupCommand, EnvCommand): name = "show" description = "Shows information about packages." - arguments = [argument("package", "The package to inspect", optional=True)] - options = [ + arguments: ClassVar[list[Argument]] = [ + argument("package", "The package to inspect", optional=True) + ] + options: ClassVar[list[Option]] = [ *GroupCommand._group_dependency_options(), option( "no-dev", @@ -69,7 +74,7 @@ class ShowCommand(GroupCommand, EnvCommand): help = """The show command displays detailed information about a package, or lists all packages available.""" - colors = ["cyan", "yellow", "green", "magenta", "blue"] + colors: ClassVar[list[str]] = ["cyan", "yellow", "green", "magenta", "blue"] def handle(self) -> int: package = self.argument("package") diff --git a/src/poetry/console/commands/source/add.py b/src/poetry/console/commands/source/add.py index 6d1ab587ee6..9ce8ecc651d 100644 --- a/src/poetry/console/commands/source/add.py +++ b/src/poetry/console/commands/source/add.py @@ -1,5 +1,8 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from cleo.helpers import option from cleo.io.null_io import NullIO @@ -10,11 +13,16 @@ from poetry.repositories.repository_pool import Priority +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class SourceAddCommand(Command): name = "source add" description = "Add source configuration for project." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "name", "Source repository name.", @@ -27,7 +35,7 @@ class SourceAddCommand(Command): ), ] - options = [ + options: ClassVar[list[Option]] = [ option( "default", "d", diff --git a/src/poetry/console/commands/source/remove.py b/src/poetry/console/commands/source/remove.py index cb667aa5ea1..776cc658737 100644 --- a/src/poetry/console/commands/source/remove.py +++ b/src/poetry/console/commands/source/remove.py @@ -1,16 +1,23 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from tomlkit.items import AoT from poetry.console.commands.command import Command +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + + class SourceRemoveCommand(Command): name = "source remove" description = "Remove source configured for the project." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "name", "Source repository name.", diff --git a/src/poetry/console/commands/source/show.py b/src/poetry/console/commands/source/show.py index 26b85544911..61b3375ba53 100644 --- a/src/poetry/console/commands/source/show.py +++ b/src/poetry/console/commands/source/show.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING +from typing import ClassVar from cleo.helpers import argument @@ -8,6 +9,7 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument from cleo.ui.table import Rows @@ -15,7 +17,7 @@ class SourceShowCommand(Command): name = "source show" description = "Show information about sources configured for the project." - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "source", "Source(s) to show information for. Defaults to showing all sources.", diff --git a/src/poetry/console/commands/update.py b/src/poetry/console/commands/update.py index 59c17caaa9b..dc300231d27 100644 --- a/src/poetry/console/commands/update.py +++ b/src/poetry/console/commands/update.py @@ -1,21 +1,29 @@ from __future__ import annotations +from typing import TYPE_CHECKING +from typing import ClassVar + from cleo.helpers import argument from cleo.helpers import option from poetry.console.commands.installer_command import InstallerCommand +if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option + + class UpdateCommand(InstallerCommand): name = "update" description = ( "Update the dependencies as according to the pyproject.toml file." ) - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument("packages", "The packages to update", optional=True, multiple=True) ] - options = [ + options: ClassVar[list[Option]] = [ *InstallerCommand._group_dependency_options(), option( "no-dev", @@ -38,7 +46,7 @@ class UpdateCommand(InstallerCommand): option("lock", None, "Do not perform operations (only update the lockfile)."), ] - loggers = ["poetry.repositories.pypi_repository"] + loggers: ClassVar[list[str]] = ["poetry.repositories.pypi_repository"] def handle(self) -> int: packages = self.argument("packages") diff --git a/src/poetry/console/commands/version.py b/src/poetry/console/commands/version.py index 7e8d118759c..a1dbf7102ee 100644 --- a/src/poetry/console/commands/version.py +++ b/src/poetry/console/commands/version.py @@ -2,6 +2,7 @@ from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from cleo.helpers import argument from cleo.helpers import option @@ -12,6 +13,8 @@ if TYPE_CHECKING: + from cleo.io.inputs.argument import Argument + from cleo.io.inputs.option import Option from poetry.core.constraints.version import Version @@ -22,14 +25,14 @@ class VersionCommand(Command): "bump rule is provided." ) - arguments = [ + arguments: ClassVar[list[Argument]] = [ argument( "version", "The version number or the rule to update the version.", optional=True, ), ] - options = [ + options: ClassVar[list[Option]] = [ option("short", "s", "Output the version number only"), option( "dry-run", @@ -48,7 +51,7 @@ class VersionCommand(Command): patch, minor, major, prepatch, preminor, premajor, prerelease. """ - RESERVED = { + RESERVED: ClassVar[set[str]] = { "major", "minor", "patch", diff --git a/src/poetry/console/logging/io_formatter.py b/src/poetry/console/logging/io_formatter.py index 013150130a9..37432a9de76 100644 --- a/src/poetry/console/logging/io_formatter.py +++ b/src/poetry/console/logging/io_formatter.py @@ -6,6 +6,7 @@ from pathlib import Path from typing import TYPE_CHECKING +from typing import ClassVar from poetry.console.logging.filters import POETRY_FILTER from poetry.console.logging.formatters import FORMATTERS @@ -16,7 +17,7 @@ class IOFormatter(logging.Formatter): - _colors = { + _colors: ClassVar[dict[str, str]] = { "error": "fg=red", "warning": "fg=yellow", "debug": "debug",