From 69a40f27fbdcc02e3faa6ae171c00179c15604bc Mon Sep 17 00:00:00 2001 From: Bartek Sokorski Date: Wed, 19 Jul 2023 15:41:53 +0200 Subject: [PATCH] Apply changes to satisfy RUF012 rule --- pyproject.toml | 3 +++ src/poetry/config/config.py | 3 ++- src/poetry/packages/locker.py | 10 ++++++++-- src/poetry/puzzle/provider.py | 3 ++- src/poetry/repositories/link_sources/base.py | 3 ++- src/poetry/utils/setup_reader.py | 5 +++-- tests/console/test_application.py | 3 ++- tests/plugins/test_plugin_manager.py | 4 +++- 8 files changed, 25 insertions(+), 9 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 50e7829aaed..4776b608705 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,6 +135,9 @@ known-first-party = ["poetry"] known-third-party = ["poetry.core"] required-imports = ["from __future__ import annotations"] +[tool.ruff.per-file-ignores] +"src/poetry/console/*" = ["RUF012"] # Can't annotate properly until new version of Cleo + [tool.black] target-version = ['py38'] preview = true diff --git a/src/poetry/config/config.py b/src/poetry/config/config.py index b19bb16afb9..6d7658645ae 100644 --- a/src/poetry/config/config.py +++ b/src/poetry/config/config.py @@ -9,6 +9,7 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from packaging.utils import canonicalize_name @@ -104,7 +105,7 @@ def validator(cls, policy: str) -> bool: class Config: - default_config: dict[str, Any] = { + default_config: ClassVar[dict[str, Any]] = { "cache-dir": str(DEFAULT_CACHE_DIR), "virtualenvs": { "create": True, diff --git a/src/poetry/packages/locker.py b/src/poetry/packages/locker.py index a0cbfb24f51..69adb802ef6 100644 --- a/src/poetry/packages/locker.py +++ b/src/poetry/packages/locker.py @@ -9,6 +9,7 @@ from pathlib import Path from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from typing import cast from packaging.utils import canonicalize_name @@ -50,8 +51,13 @@ class Locker: _VERSION = "2.0" _READ_VERSION_RANGE = ">=1,<3" - _legacy_keys = ["dependencies", "source", "extras", "dev-dependencies"] - _relevant_keys = [*_legacy_keys, "group"] + _legacy_keys: ClassVar[list[str]] = [ + "dependencies", + "source", + "extras", + "dev-dependencies", + ] + _relevant_keys: ClassVar[list[str]] = [*_legacy_keys, "group"] def __init__(self, lock: Path, local_config: dict[str, Any]) -> None: self._lock = lock diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index ea1eb8d9559..e8204fffcf3 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -7,6 +7,7 @@ from collections import defaultdict from contextlib import contextmanager from typing import TYPE_CHECKING +from typing import ClassVar from typing import cast from cleo.ui.progress_indicator import ProgressIndicator @@ -93,7 +94,7 @@ def _formatter_elapsed(self) -> str: class Provider: - UNSAFE_PACKAGES: set[str] = set() + UNSAFE_PACKAGES: ClassVar[set[str]] = set() def __init__( self, diff --git a/src/poetry/repositories/link_sources/base.py b/src/poetry/repositories/link_sources/base.py index b2bd455d42a..9948ec8cd35 100644 --- a/src/poetry/repositories/link_sources/base.py +++ b/src/poetry/repositories/link_sources/base.py @@ -5,6 +5,7 @@ from functools import cached_property from typing import TYPE_CHECKING +from typing import ClassVar from typing import DefaultDict from typing import List @@ -31,7 +32,7 @@ class LinkSource: VERSION_REGEX = re.compile(r"(?i)([a-z0-9_\-.]+?)-(?=\d)([a-z0-9_.!+-]+)") CLEAN_REGEX = re.compile(r"[^a-z0-9$&+,/:;=?@.#%_\\|-]", re.I) - SUPPORTED_FORMATS = [ + SUPPORTED_FORMATS: ClassVar[list[str]] = [ ".tar.gz", ".whl", ".zip", diff --git a/src/poetry/utils/setup_reader.py b/src/poetry/utils/setup_reader.py index f9cecc4335a..53cd5e9e68e 100644 --- a/src/poetry/utils/setup_reader.py +++ b/src/poetry/utils/setup_reader.py @@ -5,6 +5,7 @@ from configparser import ConfigParser from typing import TYPE_CHECKING from typing import Any +from typing import ClassVar from poetry.core.constraints.version import Version @@ -18,7 +19,7 @@ class SetupReader: Class that reads a setup.py file without executing it. """ - DEFAULT: dict[str, Any] = { + DEFAULT: ClassVar[dict[str, Any]] = { "name": None, "version": None, "install_requires": [], @@ -26,7 +27,7 @@ class SetupReader: "python_requires": None, } - FILES = ["setup.py", "setup.cfg"] + FILES: ClassVar[list[str]] = ["setup.py", "setup.cfg"] @classmethod def read_from_directory(cls, directory: Path) -> dict[str, Any]: diff --git a/tests/console/test_application.py b/tests/console/test_application.py index 21310a81478..931944e227f 100644 --- a/tests/console/test_application.py +++ b/tests/console/test_application.py @@ -3,6 +3,7 @@ import re from typing import TYPE_CHECKING +from typing import ClassVar import pytest @@ -32,7 +33,7 @@ def handle(self) -> int: class AddCommandPlugin(ApplicationPlugin): - commands = [FooCommand] + commands: ClassVar[list[type[Command]]] = [FooCommand] @pytest.fixture diff --git a/tests/plugins/test_plugin_manager.py b/tests/plugins/test_plugin_manager.py index 7ac296b8ef9..b6baa358ec7 100644 --- a/tests/plugins/test_plugin_manager.py +++ b/tests/plugins/test_plugin_manager.py @@ -2,6 +2,7 @@ from pathlib import Path from typing import TYPE_CHECKING +from typing import ClassVar from typing import Protocol import pytest @@ -22,6 +23,7 @@ from cleo.io.io import IO from pytest_mock import MockerFixture + from poetry.console.commands.command import Command from tests.conftest import Config from tests.types import FixtureDirGetter @@ -38,7 +40,7 @@ def activate(self, poetry: Poetry, io: IO) -> None: class MyCommandPlugin(ApplicationPlugin): - commands = [] + commands: ClassVar[list[type[Command]]] = [] class InvalidPlugin: