Skip to content

Commit

Permalink
ci: Run pyupgrade with Ruff (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan authored Jan 20, 2025
1 parent 3b09b66 commit 2080fc0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: [--py39-plus, --keep-runtime-typing]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: "v0.7.0"
hooks:
Expand Down
4 changes: 2 additions & 2 deletions docs/scripts/utils/commands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from functools import lru_cache
from functools import cache
from typing import Any
from typing import Optional
from typing import Union
Expand Down Expand Up @@ -276,7 +276,7 @@ def get_command_help(command: typer.models.CommandInfo) -> str:
return ""


@lru_cache(maxsize=None)
@cache
def get_app_commands(app: typer.Typer) -> list[CommandSummary]:
"""Get a list of commands from a typer app."""
return _get_app_commands(app)
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ extend-select = [
"TID252", # flake8-tidy-imports (prefer absolute imports)
"C4", # flake8-comprehensions
"B", # flake8-bugbear
"UP", # pyupgrade
]
ignore = [
"E501", # Avoid enforcing line-length violations
Expand All @@ -182,3 +183,7 @@ ignore = [
force-single-line = true
# Add annotations import to every file
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.pyupgrade]
# Preserve types, even if a file imports `from __future__ import annotations`.
keep-runtime-typing = true
20 changes: 20 additions & 0 deletions tests/test_repl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from __future__ import annotations

from inline_snapshot import snapshot
from zabbix_cli.repl.repl import _help_internal # pyright: ignore[reportPrivateUsage]


def test_help_internal() -> None:
assert _help_internal() == snapshot(
"""\
REPL help:
External Commands:
prefix external commands with "!"
Internal Commands:
prefix internal commands with ":"
:exit, :q, :quit exits the repl
:?, :h, :help displays general help information
"""
)
4 changes: 2 additions & 2 deletions zabbix_cli/output/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import math
import os
from functools import lru_cache
from functools import cache
from functools import wraps
from pathlib import Path
from typing import Any
Expand Down Expand Up @@ -66,7 +66,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:


# NOTE: if testing this function, clear cache after each test
@lru_cache(maxsize=None)
@cache
def is_headless() -> bool:
"""Determines if we are running in a headless environment (e.g. CI, Docker, etc.)"""
# Truthy values indicate headless
Expand Down
3 changes: 1 addition & 2 deletions zabbix_cli/repl/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import TYPE_CHECKING
from typing import Any
from typing import Callable
from typing import DefaultDict
from typing import NamedTuple
from typing import NoReturn
from typing import Optional
Expand Down Expand Up @@ -83,7 +82,7 @@ def _help_internal() -> str:
formatter.write_text('prefix external commands with "!"')
with formatter.section("Internal Commands"):
formatter.write_text('prefix internal commands with ":"')
info_table: DefaultDict[str, list[str]] = defaultdict(list)
info_table: defaultdict[str, list[str]] = defaultdict(list)
for mnemonic, target_info in _internal_commands.items():
info_table[target_info[1]].append(mnemonic)
formatter.write_dl(
Expand Down

0 comments on commit 2080fc0

Please sign in to comment.