From d05af3ac9655afbbea43a5ddf82d8ad3d8287a4e Mon Sep 17 00:00:00 2001 From: Alex Ruddick Date: Sat, 14 Sep 2024 14:31:59 -0500 Subject: [PATCH] from __future__ import annotations --- pymodbus_repl/client/mclient.py | 4 ++-- pymodbus_repl/server/cli.py | 13 +++++++------ pymodbus_repl/server/main.py | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/pymodbus_repl/client/mclient.py b/pymodbus_repl/client/mclient.py index 85ddb0f..0ca74a0 100644 --- a/pymodbus_repl/client/mclient.py +++ b/pymodbus_repl/client/mclient.py @@ -6,6 +6,8 @@ from pymodbus.client import ModbusSerialClient as _ModbusSerialClient from pymodbus.client import ModbusTcpClient as _ModbusTcpClient from pymodbus.client.base import ModbusBaseSyncClient as _ModbusBaseSyncClient +from pymodbus.exceptions import ModbusIOException +from pymodbus.pdu import ExceptionResponse, ModbusExceptions from pymodbus.pdu.diag_message import ( ChangeAsciiInputDelimiterRequest, ClearCountersRequest, @@ -26,7 +28,6 @@ ReturnSlaveNAKCountRequest, ReturnSlaveNoResponseCountRequest, ) -from pymodbus.exceptions import ModbusIOException from pymodbus.pdu.mei_message import ( ReadDeviceInformationRequest, ReadDeviceInformationResponse, @@ -41,7 +42,6 @@ ReportSlaveIdRequest, ReportSlaveIdResponse, ) -from pymodbus.pdu import ExceptionResponse, ModbusExceptions from pymodbus.pdu.register_write_message import MaskWriteRegisterResponse diff --git a/pymodbus_repl/server/cli.py b/pymodbus_repl/server/cli.py index b5d2451..0617a23 100644 --- a/pymodbus_repl/server/cli.py +++ b/pymodbus_repl/server/cli.py @@ -1,9 +1,10 @@ """Repl server cli.""" +from __future__ import annotations + import functools import inspect import shutil from collections import defaultdict -from typing import Dict, Optional import click from prompt_toolkit import PromptSession, print_formatted_text @@ -40,7 +41,7 @@ ) COMMAND_ARGS = ["response_type", "error_code", "delay_by", "clear_after", "data_len"] RESPONSE_TYPES = ["normal", "error", "delayed", "empty", "stray"] -COMMANDS: Dict[str, Optional[Dict | Command]] = { +COMMANDS: dict[str, dict | Command | None] = { "manipulator": { "response_type": None, "error_code": None, @@ -78,9 +79,9 @@ } -def manipulator_to_dict(response_type: str = 'normal', error_code: Optional[int] = None, - delay_by: Optional[float] = None, - clear_after: Optional[int] = None) -> dict: +def manipulator_to_dict(response_type: str = 'normal', error_code: int | None = None, + delay_by: float | None = None, + clear_after: int | None = None) -> dict: """ Manipulate response from the server. @@ -147,7 +148,7 @@ def get_terminal_width(): return shutil.get_terminal_size()[0] -def print_help(command: Optional[str] = None): +def print_help(command: str | None = None): """Print help.""" def _print_formatted(cmd: str, hlp: str): diff --git a/pymodbus_repl/server/main.py b/pymodbus_repl/server/main.py index 57b3e0f..d47c43e 100644 --- a/pymodbus_repl/server/main.py +++ b/pymodbus_repl/server/main.py @@ -12,8 +12,8 @@ import typer from pymodbus import pymodbus_apply_logging_config -from pymodbus.transaction import ModbusSocketFramer from pymodbus.logging import Log +from pymodbus.transaction import ModbusSocketFramer from typing_extensions import Annotated from pymodbus_repl.lib.reactive import (