diff --git a/examples/pymeasure_actor.py b/examples/pymeasure_actor.py index 426f0b74..d952c94f 100644 --- a/examples/pymeasure_actor.py +++ b/examples/pymeasure_actor.py @@ -10,7 +10,7 @@ from pyleco.actors.actor import Actor from pyleco.utils.publisher import Publisher -from pymeasure.instruments.ipgphotonics import YAR +from pymeasure.instruments.ipgphotonics import YAR # type:ignore[import-not-found] log = logging.getLogger(__name__) log.addHandler(logging.NullHandler()) diff --git a/pyleco/actors/actor.py b/pyleco/actors/actor.py index 88564130..01ec94a4 100644 --- a/pyleco/actors/actor.py +++ b/pyleco/actors/actor.py @@ -22,13 +22,11 @@ # THE SOFTWARE. # -import time from typing import Any, Callable, Optional, Union import zmq -from ..utils.message_handler import BaseController, heartbeat_interval -from ..utils.events import Event, SimpleEvent +from ..utils.message_handler import BaseController from ..utils.publisher import Publisher from ..utils.timers import RepeatingTimer diff --git a/pyleco/coordinators/coordinator.py b/pyleco/coordinators/coordinator.py index d50075ca..3f02b070 100644 --- a/pyleco/coordinators/coordinator.py +++ b/pyleco/coordinators/coordinator.py @@ -350,8 +350,8 @@ def pong(self) -> None: @staticmethod def set_log_level(level: str) -> None: - level = PythonLogLevels[level] - log.setLevel(level) + plevel = PythonLogLevels[level] + log.setLevel(plevel) def shut_down(self) -> None: self.sign_out_from_all_coordinators() diff --git a/pyleco/directors/data_logger_director.py b/pyleco/directors/data_logger_director.py index 3dcb8406..97307958 100644 --- a/pyleco/directors/data_logger_director.py +++ b/pyleco/directors/data_logger_director.py @@ -61,10 +61,13 @@ def get_last_datapoint(self) -> dict[str, Any]: def saveData(self) -> str: """Save the data and return the name of the file.""" - tmo = self.communicator.timeout - self.communicator.timeout = 1000 - name = self.call_method_rpc("saveData") - self.communicator.timeout = tmo + try: + tmo = self.communicator.timeout # type:ignore[attr-defined] + self.communicator.timeout = 1000 # type:ignore[attr-defined] + name = self.call_method_rpc("saveData") + self.communicator.timeout = tmo # type:ignore[attr-defined] + except AttributeError: + name = self.call_method_rpc("saveData") return name def stop_collecting(self) -> None: diff --git a/pyleco/management/data_logger.py b/pyleco/management/data_logger.py index 0fe0a735..e85ca25d 100644 --- a/pyleco/management/data_logger.py +++ b/pyleco/management/data_logger.py @@ -36,7 +36,7 @@ class StrEnum(str, Enum): # type: ignore from typing import Any, Callable, Optional try: - import numpy as np # type: ignore + import numpy as np # type: ignore[import-not-found] except ModuleNotFoundError: def average(values: list[float | int] | tuple[float | int, ...]): return sum(values) / len(values) @@ -143,7 +143,8 @@ def shut_down(self) -> None: def __del__(self) -> None: self.stop_collecting() - def _listen_setup(self, start_data: Optional[dict[str, Any]] = None, **kwargs): + def _listen_setup(self, start_data: Optional[dict[str, Any]] = None, # type: ignore[override] + **kwargs): poller = super()._listen_setup(**kwargs) if start_data is not None: self.start_collecting(**start_data) diff --git a/pyleco/management/data_logger_postgresql.py b/pyleco/management/data_logger_postgresql.py index d5c98233..707a70a0 100644 --- a/pyleco/management/data_logger_postgresql.py +++ b/pyleco/management/data_logger_postgresql.py @@ -26,7 +26,7 @@ import datetime from typing import Any -import psycopg2 +import psycopg2 # type: ignore[import-untyped] from .data_logger import DataLogger @@ -48,6 +48,7 @@ def __init__(self, name: str, if table is None: raise ValueError("Table must not be empty.") self.table = table + self.tries = 0 self.connect_database() def make_data_point(self): @@ -75,7 +76,7 @@ def write_database(self, data: dict[str, Any]): if self.tries < 10: self.tries += 1 else: - self.connectDatabase() + self.connect_database() self.tries = 0 return # No database connection existing. columns = "timestamp" @@ -87,7 +88,7 @@ def write_database(self, data: dict[str, Any]): cursor.execute(f"INSERT INTO {self.table} ({columns}) VALUES (%s{', %s' * length})", (datetime.datetime.now(), *data.values())) except (psycopg2.OperationalError, psycopg2.InterfaceError): - self.connectDatabase() # Connection lost, reconnect. + self.connect_database() # Connection lost, reconnect. except Exception as exc: log.exception("Database write error.", exc_info=exc) database.rollback() diff --git a/pyleco/utils/extended_publisher.py b/pyleco/utils/extended_publisher.py index 096b9a2d..690a3f5d 100644 --- a/pyleco/utils/extended_publisher.py +++ b/pyleco/utils/extended_publisher.py @@ -25,8 +25,8 @@ import json from typing import Any -import numpy as np -import pint +import numpy as np # type: ignore[import-not-found] +import pint # type: ignore[import-not-found] from pyleco.utils.publisher import Publisher diff --git a/pyleco/utils/listener.py b/pyleco/utils/listener.py index daa0b6ec..05eb9a66 100644 --- a/pyleco/utils/listener.py +++ b/pyleco/utils/listener.py @@ -93,8 +93,12 @@ def close(self) -> None: def name(self) -> str: return self.message_handler.name + @name.setter + def name(self, value: str) -> None: + self.message_handler.name = value + @property - def namespace(self) -> str | None: + def namespace(self) -> str | None: # type: ignore[override] # only the handler sets namespace. return self.message_handler.namespace @property diff --git a/pyleco/utils/message_handler.py b/pyleco/utils/message_handler.py index 8bd1c688..851e8c51 100644 --- a/pyleco/utils/message_handler.py +++ b/pyleco/utils/message_handler.py @@ -302,8 +302,8 @@ def handle_commands(self, msg: Message) -> None: def set_log_level(self, level: str) -> None: """Set the log level.""" - level = PythonLogLevels[level] - self.root_logger.setLevel(level) + plevel = PythonLogLevels[level] + self.root_logger.setLevel(plevel) def shut_down(self) -> None: self.stop_event.set() diff --git a/tests/acceptance_tests/test_proxy_server_live.py b/tests/acceptance_tests/test_proxy_server_live.py index fcb1929d..ad846277 100644 --- a/tests/acceptance_tests/test_proxy_server_live.py +++ b/tests/acceptance_tests/test_proxy_server_live.py @@ -43,7 +43,7 @@ class ModListener(Listener): def __init__(self, name: str, host: str = "localhost", data_port: int = PROXY_SENDING_PORT, **kwargs) -> None: super().__init__(name=name, host=host, data_port=data_port, **kwargs) - self._data = [] + self._data: list[dict] = [] def handle_subscription_data(self, data: dict) -> None: self._data.append(data) @@ -55,7 +55,7 @@ def publisher() -> Publisher: @pytest.fixture(scope="module") -def listener(publisher) -> ModListener: +def listener(publisher): context = start_proxy(offset=offset) listener = ModListener(name="listener", data_port=port - 1 - 2 * offset) listener.start_listen() diff --git a/tests/utils/test_listener.py b/tests/utils/test_listener.py index 25ac8c95..554cb79a 100644 --- a/tests/utils/test_listener.py +++ b/tests/utils/test_listener.py @@ -48,7 +48,7 @@ def __init__(self, received: list[Message] | None = None) -> None: self._sent: list[Message] = [] self._received: list[Message] = received or [] - def pipe_setup(self) -> None: + def pipe_setup(self, context=None) -> None: # type: ignore[override] pass def pipe_send_message(self, message: Message) -> None: diff --git a/tests/utils/test_pipe_handler.py b/tests/utils/test_pipe_handler.py index cb1254d3..3fe4970c 100644 --- a/tests/utils/test_pipe_handler.py +++ b/tests/utils/test_pipe_handler.py @@ -127,7 +127,7 @@ def test_retrieve_message_after_waiting(message_buffer: MessageBuffer): def fake_check_message_in_buffer(conversation_id: bytes) -> Message | None: return msg_list.pop(0) - message_buffer._check_message_in_buffer = fake_check_message_in_buffer + message_buffer._check_message_in_buffer = fake_check_message_in_buffer # type:ignore message_buffer._event.set() # Act + Assert assert message_buffer.retrieve_message(conversation_id=cid) == msg