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

[pre-commit.ci] pre-commit autoupdate #335

Merged
merged 2 commits into from
Jul 18, 2023
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ ci:

repos:
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
hooks:
- id: ruff
6 changes: 4 additions & 2 deletions src/cleo/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import os

from typing import ClassVar

from cleo.exceptions import CleoValueError


class Color:
COLORS = {
COLORS: ClassVar[dict[str, tuple[int, int]]] = {
"black": (30, 40),
"red": (31, 41),
"green": (32, 42),
Expand All @@ -26,7 +28,7 @@ class Color:
"white": (97, 107),
}

AVAILABLE_OPTIONS = {
AVAILABLE_OPTIONS: ClassVar[dict[str, dict[str, int]]] = {
"bold": {"set": 1, "unset": 22},
"dark": {"set": 2, "unset": 22},
"italic": {"set": 3, "unset": 23},
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/commands/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import inspect

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.exceptions import CleoError
from cleo.io.inputs.definition import Definition
Expand All @@ -23,7 +24,7 @@ class BaseCommand:
enabled = True
hidden = False

usages: list[str] = []
usages: ClassVar[list[str]] = []

def __init__(self) -> None:
self._definition = Definition()
Expand Down
11 changes: 6 additions & 5 deletions src/cleo/commands/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import TYPE_CHECKING
from typing import Any
from typing import ClassVar
from typing import ContextManager
from typing import cast

Expand Down Expand Up @@ -32,11 +33,11 @@


class Command(BaseCommand):
arguments: list[Argument] = []
options: list[Option] = []
aliases: list[str] = []
usages: list[str] = []
commands: list[BaseCommand] = []
arguments: ClassVar[list[Argument]] = []
options: ClassVar[list[Option]] = []
aliases: ClassVar[list[str]] = []
usages: ClassVar[list[str]] = []
commands: ClassVar[list[BaseCommand]] = []

def __init__(self) -> None:
self._io: IO = None # type: ignore[assignment]
Expand Down
12 changes: 10 additions & 2 deletions src/cleo/commands/completions_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,30 @@
import re
import subprocess

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo import helpers
from cleo._compat import shell_quote
from cleo.commands.command import Command
from cleo.commands.completions.templates import TEMPLATES


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option


class CompletionsCommand(Command):
name = "completions"
description = "Generate completion scripts for your shell."

arguments = [
arguments: ClassVar[list[Argument]] = [
helpers.argument(
"shell", "The shell to generate the scripts for.", optional=True
)
]
options = [
options: ClassVar[list[Option]] = [
helpers.option(
"alias", None, "Alias for the current command.", flag=False, multiple=True
)
Expand Down
4 changes: 3 additions & 1 deletion src/cleo/commands/help_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command
from cleo.io.inputs.argument import Argument

Expand All @@ -9,7 +11,7 @@ class HelpCommand(Command):

description = "Displays help for a command."

arguments = [
arguments: ClassVar[list[Argument]] = [
Argument(
"command_name",
required=False,
Expand Down
4 changes: 3 additions & 1 deletion src/cleo/commands/list_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command
from cleo.io.inputs.argument import Argument

Expand All @@ -19,7 +21,7 @@ class ListCommand(Command):
<info>{command_full_name} test</info>
"""

arguments = [
arguments: ClassVar[list[Argument]] = [
Argument("namespace", required=False, description="The namespace name")
]

Expand Down
4 changes: 3 additions & 1 deletion src/cleo/formatters/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import re

from typing import ClassVar

from cleo.exceptions import CleoValueError
from cleo.formatters.style import Style
from cleo.formatters.style_stack import StyleStack
Expand All @@ -10,7 +12,7 @@
class Formatter:
TAG_REGEX = re.compile(r"(?ix)<(([a-z](?:[^<>]*)) | /([a-z](?:[^<>]*))?)>")

_inline_styles_cache: dict[str, Style] = {}
_inline_styles_cache: ClassVar[dict[str, Style]] = {}

def __init__(
self, decorated: bool = False, styles: dict[str, Style] | None = None
Expand Down
15 changes: 8 additions & 7 deletions src/cleo/ui/exception_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tokenize

from typing import TYPE_CHECKING
from typing import ClassVar

from crashtest.frame_collection import FrameCollection

Expand Down Expand Up @@ -38,7 +39,7 @@ class Highlighter:
LINE_MARKER = "line_marker"
LINE_NUMBER = "line_number"

DEFAULT_THEME = {
DEFAULT_THEME: ClassVar[dict[str, str]] = {
TOKEN_STRING: "fg=yellow;options=bold",
TOKEN_NUMBER: "fg=blue;options=bold",
TOKEN_COMMENT: "fg=default;options=dark,italic",
Expand All @@ -50,10 +51,10 @@ class Highlighter:
LINE_NUMBER: "fg=default;options=dark",
}

KEYWORDS = set(keyword.kwlist)
BUILTINS = set(dir(builtins))
KEYWORDS: ClassVar[set[str]] = set(keyword.kwlist)
BUILTINS: ClassVar[set[str]] = set(dir(builtins))

UI = {
UI: ClassVar[dict[bool, dict[str, str]]] = {
False: {"arrow": ">", "delimiter": "|"},
True: {"arrow": "→", "delimiter": "│"},
}
Expand Down Expand Up @@ -209,14 +210,14 @@ class ExceptionTrace:
Renders the trace of an exception.
"""

THEME = {
THEME: ClassVar[dict[str, str]] = {
"comment": "<fg=black;options=bold>",
"keyword": "<fg=yellow>",
"builtin": "<fg=blue>",
"literal": "<fg=magenta>",
}

AST_ELEMENTS = {
AST_ELEMENTS: ClassVar[dict[str, list[str]]] = {
"builtins": dir(builtins),
"keywords": [
getattr(ast, cls)
Expand All @@ -227,7 +228,7 @@ class ExceptionTrace:
],
}

_FRAME_SNIPPET_CACHE: dict[tuple[Frame, int, int], list[str]] = {}
_FRAME_SNIPPET_CACHE: ClassVar[dict[tuple[Frame, int, int], list[str]]] = {}

def __init__(
self,
Expand Down
3 changes: 2 additions & 1 deletion src/cleo/ui/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import time

from typing import TYPE_CHECKING
from typing import ClassVar
from typing import Match

from cleo._utils import format_time
Expand Down Expand Up @@ -33,7 +34,7 @@ class ProgressBar(Component):
progress_char = ">"
redraw_freq: int | None = 1

formats = {
formats: ClassVar[dict[str, str]] = {
"normal": " %current%/%max% [%bar%] %percent:3s%%",
"normal_nomax": " %current% [%bar%]",
"verbose": " %current%/%max% [%bar%] %percent:3s%% %elapsed:-6s%",
Expand Down
9 changes: 8 additions & 1 deletion tests/commands/completion/fixtures/command_with_colons.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.commands.command import Command
from cleo.helpers import option


if TYPE_CHECKING:
from cleo.io.inputs.option import Option


class CommandWithColons(Command):
name = "command:with:colons"
options = [option("goodbye")]
options: ClassVar[list[Option]] = [option("goodbye")]
description = "Test."
14 changes: 12 additions & 2 deletions tests/commands/completion/fixtures/command_with_space_in_name.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.commands.command import Command
from cleo.helpers import argument
from cleo.helpers import option


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument
from cleo.io.inputs.option import Option


class SpacedCommand(Command):
name = "spaced command"
description = "Command with space in name."
arguments = [argument("test", description="test argument")]
options = [option("goodbye")]
arguments: ClassVar[list[Argument]] = [
argument("test", description="test argument")
]
options: ClassVar[list[Option]] = [option("goodbye")]
9 changes: 8 additions & 1 deletion tests/commands/completion/fixtures/hello_command.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.commands.command import Command
from cleo.helpers import option


if TYPE_CHECKING:
from cleo.io.inputs.option import Option


class HelloCommand(Command):
name = "hello"
options = [
options: ClassVar[list[Option]] = [
option(
"dangerous-option",
flag=False,
Expand Down
13 changes: 11 additions & 2 deletions tests/commands/test_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import ClassVar

from cleo.application import Application
from cleo.commands.command import Command
from cleo.helpers import argument
Expand All @@ -8,9 +11,15 @@
from tests.fixtures.signature_command import SignatureCommand


if TYPE_CHECKING:
from cleo.io.inputs.argument import Argument


class MyCommand(Command):
name = "test"
arguments = [argument("action", description="The action to execute.")]
arguments: ClassVar[list[Argument]] = [
argument("action", description="The action to execute.")
]

def handle(self) -> int:
action = self.argument("action")
Expand All @@ -27,7 +36,7 @@ class MySecondCommand(Command):
name = "test2"
description = "Command testing"

arguments = [argument("foo", "Bar", multiple=True)]
arguments: ClassVar[list[Argument]] = [argument("foo", "Bar", multiple=True)]

def handle(self) -> int:
foos = self.argument("foo")
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/foo1_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command


Expand All @@ -8,7 +10,7 @@ class Foo1Command(Command):

description = "The foo bar1 command"

aliases = ["afoobar1"]
aliases: ClassVar[list[str]] = ["afoobar1"]

def handle(self) -> int:
return 0
4 changes: 3 additions & 1 deletion tests/fixtures/foo2_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command


Expand All @@ -8,7 +10,7 @@ class Foo2Command(Command):

description = "The foo1 bar command"

aliases = ["afoobar2"]
aliases: ClassVar[list[str]] = ["afoobar2"]

def handle(self) -> int:
return 0
4 changes: 3 additions & 1 deletion tests/fixtures/foo3_command.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

from cleo.commands.command import Command


Expand All @@ -8,7 +10,7 @@ class Foo3Command(Command):

description = "The foo3 bar command"

aliases = ["foo3"]
aliases: ClassVar[list[str]] = ["foo3"]

def handle(self) -> int:
question = self.ask("echo:", default="default input")
Expand Down
Loading
Loading