Skip to content

Commit 031caee

Browse files
committed
fix: adapt styling rules per ty issues
Issue: https://progress.opensuse.org/issues/198026
1 parent 6699175 commit 031caee

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

check-netbox-unused-machine-power.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,21 @@
77
indicating it may still be powered on despite being decommissioned or unused.
88
"""
99

10+
from __future__ import annotations
11+
1012
import os
1113
import re
1214
import sys
15+
from typing import TYPE_CHECKING
1316
from urllib.parse import urlparse
1417

1518
import netsnmp
1619
import pynetbox
1720
from pynetbox.models import dcim
1821

22+
if TYPE_CHECKING:
23+
from pynetbox.models import dcim
24+
1925
BACHMANN_RELAY_ON = 19 # Bachmann PDU relay status value for "on"
2026

2127
verbose = os.environ.get("VERBOSE") == "1"
@@ -74,7 +80,7 @@ def green(s: str) -> str:
7480
return f"\x1b[32m{s}\x1b[0m"
7581

7682

77-
def print_device(device: dcim.Devices, dev_pdu_power: dict, watts: int) -> None:
83+
def print_device(device: dcim.Devices, dev_pdu_power: dict[str, tuple[str, str]], watts: int) -> None:
7884
"""Report device power consumption per PDU outlet for human review."""
7985
s = " " if verbose else ""
8086
pdu_power = " ".join([f"{h}:{green(p) if s else red(p)}={w}W" for (h, p), (w, s) in dev_pdu_power.items()])

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ allowed-unresolved-imports = ["netsnmp"]
146146
author = "SUSE LLC"
147147
notice-rgx = "Copyright"
148148

149+
[tool.ty.rules]
150+
# sh uses __getattr__ to dynamically wrap system commands (e.g. ping), so its
151+
# members are not statically resolvable. netsnmp is a C extension installed as
152+
# a system package (python3-netsnmp) and has no stubs available on PyPI.
153+
unresolved-import = "ignore"
154+
149155
[tool.ruff.lint.flake8-tidy-imports.banned-api]
150156
"os.system".msg = "Use `subprocess.run` or `sh` library instead."
151157
"subprocess.call".msg = "Use `subprocess.run` with `check=True`."

tests/test_trigger_bisect_jobs.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import re
1010
import subprocess # noqa: S404
1111
from argparse import Namespace
12-
from typing import Any
12+
from typing import Any, cast
1313
from unittest.mock import MagicMock, call, patch
1414
from urllib.parse import urlparse
1515

@@ -20,7 +20,8 @@
2020

2121
loader = importlib.machinery.SourceFileLoader("openqa", f"{rootpath}/openqa-trigger-bisect-jobs")
2222
spec = importlib.util.spec_from_loader(loader.name, loader)
23-
openqa = importlib.util.module_from_spec(spec)
23+
assert spec is not None
24+
openqa = cast("Any", importlib.util.module_from_spec(spec))
2425
loader.exec_module(openqa)
2526

2627
Incident = openqa.Incident
@@ -36,11 +37,11 @@ def args_factory() -> Namespace:
3637

3738
def mocked_fetch_url(url: str, request_type: str = "text") -> Any:
3839
content = ""
39-
url = urlparse(url)
40+
parsed = urlparse(url)
4041

41-
if url.scheme in {"http", "https"}:
42-
path = url.geturl()
43-
path = path[len(url.scheme) + 3 :]
42+
if parsed.scheme in {"http", "https"}:
43+
path = parsed.geturl()
44+
path = path[len(parsed.scheme) + 3 :]
4445
path = "tests/data/python-requests/" + path
4546
content = pathlib.Path(path).read_text(encoding="utf-8")
4647
if request_type == "json":

0 commit comments

Comments
 (0)