Skip to content

Commit 2080fc0

Browse files
authored
ci: Run pyupgrade with Ruff (#286)
1 parent 3b09b66 commit 2080fc0

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ repos:
88
- id: end-of-file-fixer
99
- id: check-yaml
1010
- id: check-added-large-files
11-
- repo: https://github.com/asottile/pyupgrade
12-
rev: v3.19.0
13-
hooks:
14-
- id: pyupgrade
15-
args: [--py39-plus, --keep-runtime-typing]
1611
- repo: https://github.com/charliermarsh/ruff-pre-commit
1712
rev: "v0.7.0"
1813
hooks:

docs/scripts/utils/commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from functools import lru_cache
3+
from functools import cache
44
from typing import Any
55
from typing import Optional
66
from typing import Union
@@ -276,7 +276,7 @@ def get_command_help(command: typer.models.CommandInfo) -> str:
276276
return ""
277277

278278

279-
@lru_cache(maxsize=None)
279+
@cache
280280
def get_app_commands(app: typer.Typer) -> list[CommandSummary]:
281281
"""Get a list of commands from a typer app."""
282282
return _get_app_commands(app)

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ extend-select = [
170170
"TID252", # flake8-tidy-imports (prefer absolute imports)
171171
"C4", # flake8-comprehensions
172172
"B", # flake8-bugbear
173+
"UP", # pyupgrade
173174
]
174175
ignore = [
175176
"E501", # Avoid enforcing line-length violations
@@ -182,3 +183,7 @@ ignore = [
182183
force-single-line = true
183184
# Add annotations import to every file
184185
required-imports = ["from __future__ import annotations"]
186+
187+
[tool.ruff.lint.pyupgrade]
188+
# Preserve types, even if a file imports `from __future__ import annotations`.
189+
keep-runtime-typing = true

tests/test_repl.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from __future__ import annotations
2+
3+
from inline_snapshot import snapshot
4+
from zabbix_cli.repl.repl import _help_internal # pyright: ignore[reportPrivateUsage]
5+
6+
7+
def test_help_internal() -> None:
8+
assert _help_internal() == snapshot(
9+
"""\
10+
REPL help:
11+
12+
External Commands:
13+
prefix external commands with "!"
14+
15+
Internal Commands:
16+
prefix internal commands with ":"
17+
:exit, :q, :quit exits the repl
18+
:?, :h, :help displays general help information
19+
"""
20+
)

zabbix_cli/output/prompts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
import math
55
import os
6-
from functools import lru_cache
6+
from functools import cache
77
from functools import wraps
88
from pathlib import Path
99
from typing import Any
@@ -66,7 +66,7 @@ def wrapper(*args: P.args, **kwargs: P.kwargs) -> T:
6666

6767

6868
# NOTE: if testing this function, clear cache after each test
69-
@lru_cache(maxsize=None)
69+
@cache
7070
def is_headless() -> bool:
7171
"""Determines if we are running in a headless environment (e.g. CI, Docker, etc.)"""
7272
# Truthy values indicate headless

zabbix_cli/repl/repl.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from typing import TYPE_CHECKING
1111
from typing import Any
1212
from typing import Callable
13-
from typing import DefaultDict
1413
from typing import NamedTuple
1514
from typing import NoReturn
1615
from typing import Optional
@@ -83,7 +82,7 @@ def _help_internal() -> str:
8382
formatter.write_text('prefix external commands with "!"')
8483
with formatter.section("Internal Commands"):
8584
formatter.write_text('prefix internal commands with ":"')
86-
info_table: DefaultDict[str, list[str]] = defaultdict(list)
85+
info_table: defaultdict[str, list[str]] = defaultdict(list)
8786
for mnemonic, target_info in _internal_commands.items():
8887
info_table[target_info[1]].append(mnemonic)
8988
formatter.write_dl(

0 commit comments

Comments
 (0)