From 5947e3be8992fa0e7caf8a9da14d37f542f394c6 Mon Sep 17 00:00:00 2001 From: Cyrill Raccaud Date: Thu, 19 Sep 2024 18:14:04 +0200 Subject: [PATCH] Fix mypy setup (#8) fix mypy setup --- mypi.ini => mypy.ini | 3 +-- pyproject.toml | 7 ++++++- requirements_dev.txt | 3 ++- systemctl2mqtt/helpers.py | 4 ++-- systemctl2mqtt/systemctl2mqtt.py | 12 ++++++------ 5 files changed, 17 insertions(+), 12 deletions(-) rename mypi.ini => mypy.ini (92%) diff --git a/mypi.ini b/mypy.ini similarity index 92% rename from mypi.ini rename to mypy.ini index d372c6c..b30ce17 100644 --- a/mypi.ini +++ b/mypy.ini @@ -2,14 +2,13 @@ python_version = 3.12 plugins = pydantic.mypy show_error_codes = true -follow_imports = silent local_partial_types = true strict_equality = true no_implicit_optional = true warn_incomplete_stub = true warn_redundant_casts = true warn_unused_configs = true -warn_unused_ignores = true +warn_unused_ignores = false enable_error_code = ignore-without-code, redundant-self, truthy-iterable disable_error_code = annotation-unchecked, import-not-found, import-untyped extra_checks = false diff --git a/pyproject.toml b/pyproject.toml index 6f84ab7..b2e96df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,15 @@ [build-system] requires = [ - "setuptools>=42", + "setuptools>=46.4.0", "wheel" ] build-backend = "setuptools.build_meta" +[tool.ruff] + +target-version = "py312" + + [tool.ruff.lint] select = [ "B002", # Python does not support the unary prefix increment diff --git a/requirements_dev.txt b/requirements_dev.txt index ccd9738..c74d5a4 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,6 +1,7 @@ paho-mqtt types-paho-mqtt -mypy>=1.8.0 +mypy +pydantic pre-commit>=3.6.1 python-dotenv>=1.0.1 ruff~=0.6 diff --git a/systemctl2mqtt/helpers.py b/systemctl2mqtt/helpers.py index 4b4127e..a305d3a 100644 --- a/systemctl2mqtt/helpers.py +++ b/systemctl2mqtt/helpers.py @@ -1,13 +1,13 @@ """systemctl2mqtt helpers.""" -from typing import Dict, Union +from typing import Union from .type_definitions import ServiceEntry def clean_for_discovery( val: ServiceEntry, -) -> Dict[str, Union[str, int, float, object]]: +) -> dict[str, Union[str, int, float, object]]: """Cleanup a typed dict for home assistant discovery, which is quite picky and does not like empty of None values. Parameters diff --git a/systemctl2mqtt/systemctl2mqtt.py b/systemctl2mqtt/systemctl2mqtt.py index 3722799..b377532 100755 --- a/systemctl2mqtt/systemctl2mqtt.py +++ b/systemctl2mqtt/systemctl2mqtt.py @@ -14,7 +14,7 @@ import sys from threading import Thread from time import sleep, time -from typing import Any, Dict +from typing import Any import paho.mqtt.client @@ -128,10 +128,10 @@ class Systemctl2Mqtt: systemctl_events: Queue[dict[str, str]] = Queue(maxsize=MAX_QUEUE_SIZE) systemctl_stats: Queue[list[str]] = Queue(maxsize=MAX_QUEUE_SIZE) - known_event_services: Dict[str, ServiceEvent] = {} - known_stat_services: Dict[str, Dict[int, ServiceStatsRef]] = {} - last_stat_services: Dict[str, ServiceStats | Dict[str, Any]] = {} - pending_destroy_operations: Dict[str, float] = {} + known_event_services: dict[str, ServiceEvent] = {} + known_stat_services: dict[str, dict[int, ServiceStatsRef]] = {} + last_stat_services: dict[str, ServiceStats | dict[str, Any]] = {} + pending_destroy_operations: dict[str, float] = {} mqtt: paho.mqtt.client.Client @@ -206,7 +206,7 @@ def __init__(self, cfg: Systemctl2MqttConfig, do_not_exit: bool = False): try: # Setup MQTT self.mqtt = paho.mqtt.client.Client( - callback_api_version=paho.mqtt.client.CallbackAPIVersion.VERSION2, # type: ignore + callback_api_version=paho.mqtt.client.CallbackAPIVersion.VERSION2, # type: ignore[attr-defined, call-arg] client_id=self.cfg["mqtt_client_id"], ) self.mqtt.username_pw_set(