Skip to content

Commit

Permalink
Apply changes to satisfy RUF012 rule
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Jul 19, 2023
1 parent a509ea7 commit 69a40f2
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/puzzle/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/poetry/repositories/link_sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions src/poetry/utils/setup_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -18,15 +19,15 @@ 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": [],
"extras_require": {},
"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]:
Expand Down
3 changes: 2 additions & 1 deletion tests/console/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re

from typing import TYPE_CHECKING
from typing import ClassVar

import pytest

Expand Down Expand Up @@ -32,7 +33,7 @@ def handle(self) -> int:


class AddCommandPlugin(ApplicationPlugin):
commands = [FooCommand]
commands: ClassVar[list[type[Command]]] = [FooCommand]


@pytest.fixture
Expand Down
4 changes: 3 additions & 1 deletion tests/plugins/test_plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pathlib import Path
from typing import TYPE_CHECKING
from typing import ClassVar
from typing import Protocol

import pytest
Expand All @@ -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

Expand All @@ -38,7 +40,7 @@ def activate(self, poetry: Poetry, io: IO) -> None:


class MyCommandPlugin(ApplicationPlugin):
commands = []
commands: ClassVar[list[type[Command]]] = []


class InvalidPlugin:
Expand Down

0 comments on commit 69a40f2

Please sign in to comment.