Skip to content

Commit

Permalink
pylint.
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen committed Mar 21, 2024
1 parent 769f6a3 commit 3657bc7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/package_test_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from __future__ import annotations

import asyncio
from typing import Callable
from collections.abc import Callable

import pymodbus.client as modbusClient
import pymodbus.server as modbusServer
Expand Down
7 changes: 4 additions & 3 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

import asyncio
import socket
from collections.abc import Awaitable, Callable
from dataclasses import dataclass
from typing import Any, Awaitable, Callable, Type, cast
from typing import Any, cast

from pymodbus.client.mixin import ModbusClientMixin
from pymodbus.exceptions import ConnectionException, ModbusIOException
Expand Down Expand Up @@ -90,7 +91,7 @@ def __init__(

# Common variables.
self.framer = FRAMER_NAME_TO_CLASS.get(
framer, cast(Type[ModbusFramer], framer)
framer, cast(type[ModbusFramer], framer)
)(ClientDecoder(), self)
self.transaction = ModbusTransactionManager(
self, retries=retries, retry_on_empty=retry_on_empty, **kwargs
Expand Down Expand Up @@ -344,7 +345,7 @@ def __init__(

# Common variables.
self.framer = FRAMER_NAME_TO_CLASS.get(
framer, cast(Type[ModbusFramer], framer)
framer, cast(type[ModbusFramer], framer)
)(ClientDecoder(), self)
self.transaction = ModbusTransactionManager(
self, retries=retries, retry_on_empty=retry_on_empty, **kwargs
Expand Down
3 changes: 2 additions & 1 deletion pymodbus/datastore/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import dataclasses
import random
import struct
from collections.abc import Callable
from datetime import datetime
from typing import Any, Callable
from typing import Any


WORD_SIZE = 16
Expand Down
7 changes: 4 additions & 3 deletions pymodbus/datastore/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Any, Dict, Generic, Iterable, TypeVar
from collections.abc import Iterable
from typing import Any, Generic, TypeVar

from pymodbus.exceptions import ParameterException

Expand All @@ -57,7 +58,7 @@
# Datablock Storage
# ---------------------------------------------------------------------------#

V = TypeVar('V', list, Dict[int, Any])
V = TypeVar('V', list, dict[int, Any])
class BaseModbusDataBlock(ABC, Generic[V]):
"""Base class for a modbus datastore.
Expand Down Expand Up @@ -194,7 +195,7 @@ def setValues(self, address, values):
self.values[start : start + len(values)] = values


class ModbusSparseDataBlock(BaseModbusDataBlock[Dict[int, Any]]):
class ModbusSparseDataBlock(BaseModbusDataBlock[dict[int, Any]]):
"""A sparse modbus datastore.
E.g Usage.
Expand Down
8 changes: 4 additions & 4 deletions pymodbus/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

# pylint: disable=missing-type-doc
from typing import Callable, Dict
from collections.abc import Callable

from pymodbus.bit_read_message import (
ReadCoilsRequest,
Expand Down Expand Up @@ -163,15 +163,15 @@ class ServerDecoder:
]

@classmethod
def getFCdict(cls) -> Dict[int, Callable]:
def getFCdict(cls) -> dict[int, Callable]:
"""Build function code - class list."""
return {f.function_code: f for f in cls.__function_table} # type: ignore[attr-defined]

def __init__(self) -> None:
"""Initialize the client lookup tables."""
functions = {f.function_code for f in self.__function_table} # type: ignore[attr-defined]
self.lookup = self.getFCdict()
self.__sub_lookup: Dict[int, Dict[int, Callable]] = {f: {} for f in functions}
self.__sub_lookup: dict[int, dict[int, Callable]] = {f: {} for f in functions}
for f in self.__sub_function_table:
self.__sub_lookup[f.function_code][f.sub_function_code] = f # type: ignore[attr-defined]

Expand Down Expand Up @@ -300,7 +300,7 @@ def __init__(self) -> None:
"""Initialize the client lookup tables."""
functions = {f.function_code for f in self.function_table} # type: ignore[attr-defined]
self.lookup = {f.function_code: f for f in self.function_table} # type: ignore[attr-defined]
self.__sub_lookup: Dict[int, Dict[int, Callable]] = {f: {} for f in functions}
self.__sub_lookup: dict[int, dict[int, Callable]] = {f: {} for f in functions}
for f in self.__sub_function_table:
self.__sub_lookup[f.function_code][f.sub_function_code] = f # type: ignore[attr-defined]

Expand Down
3 changes: 2 additions & 1 deletion pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@
import dataclasses
import ssl
from abc import abstractmethod
from collections.abc import Callable, Coroutine
from contextlib import suppress
from enum import Enum
from functools import partial
from typing import Any, Callable, Coroutine
from typing import Any

from pymodbus.logging import Log
from pymodbus.transport.serialtransport import create_serial_connection
Expand Down
2 changes: 1 addition & 1 deletion test/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import asyncio
from typing import Callable
from collections.abc import Callable

import pytest

Expand Down

0 comments on commit 3657bc7

Please sign in to comment.