Skip to content

Commit

Permalink
Ruff reduce ignores. (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Oct 27, 2023
1 parent 368b4c6 commit 0108921
Show file tree
Hide file tree
Showing 70 changed files with 338 additions and 350 deletions.
2 changes: 1 addition & 1 deletion examples/client_async_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ async def run_async_calls(client):


async def main(cmdline=None):
"""Combine setup and run"""
"""Combine setup and run."""
testclient = client_async.setup_async_client(
description="Run asynchronous client.", cmdline=cmdline
)
Expand Down
6 changes: 3 additions & 3 deletions examples/client_custom_msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, values=None, **kwargs):
self.values = values or []

def encode(self):
"""Encode response pdu
"""Encode response pdu.
:returns: The encoded packet message
"""
Expand All @@ -60,7 +60,7 @@ def encode(self):
return res

def decode(self, data):
"""Decode response pdu
"""Decode response pdu.
:param data: The packet data to decode
"""
Expand Down Expand Up @@ -109,7 +109,7 @@ class Read16CoilsRequest(ReadCoilsRequest):
"""Read 16 coils in one request."""

def __init__(self, address, **kwargs):
"""Initialize a new instance
"""Initialize a new instance.
:param address: The address to start reading from
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/client_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ async def run_payload_calls(client):


async def main(cmdline=None):
"""Combine the setup and run"""
"""Combine the setup and run."""
client = client_async.setup_async_client(
description="Run asynchronous client.", cmdline=cmdline
)
Expand Down
2 changes: 1 addition & 1 deletion examples/client_performance.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
"""Test performance of client: sync vs. async
"""Test performance of client: sync vs. async.
This example show how much faster the async version is.
Expand Down
4 changes: 2 additions & 2 deletions examples/datastore_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def custom_action2(_inx, _cell):


def get_commandline(cmdline=None):
"""Read and validate command line arguments"""
"""Read and validate command line arguments."""
parser = argparse.ArgumentParser(description="Run datastore simulator example.")
parser.add_argument(
"--log",
Expand Down Expand Up @@ -175,7 +175,7 @@ async def run_server_simulator(args):


async def main(cmdline=None):
"""Combine setup and run"""
"""Combine setup and run."""
run_args = setup_simulator(cmdline=cmdline)
await run_server_simulator(run_args)

Expand Down
2 changes: 1 addition & 1 deletion examples/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def get_commandline(server=False, description=None, extras=None, cmdline=None):
"""Read and validate command line arguments"""
"""Read and validate command line arguments."""
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
"-c",
Expand Down
14 changes: 7 additions & 7 deletions examples/message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def get_commandline(cmdline):
"""Parse the command line options"""
"""Parse the command line options."""
parser = argparse.ArgumentParser()

parser.add_argument(
Expand Down Expand Up @@ -63,12 +63,12 @@ class Decoder:
"""

def __init__(self, framer, encode=False):
"""Initialize a new instance of the decoder"""
"""Initialize a new instance of the decoder."""
self.framer = framer
self.encode = encode

def decode(self, message):
"""Attempt to decode the supplied message"""
"""Attempt to decode the supplied message."""
value = message if self.encode else c.encode(message, "hex_codec")
print("=" * 80)
print(f"Decoding Message {value}")
Expand All @@ -94,12 +94,12 @@ def decode(self, message):
self.check_errors(decoder, message)

def check_errors(self, decoder, message):
"""Attempt to find message errors"""
"""Attempt to find message errors."""
txt = f"Unable to parse message - {message} with {decoder}"
_logger.error(txt)

def report(self, message): # pragma no cover
"""Print the message information"""
"""Print the message information."""
print(
"%-15s = %s" # pylint: disable=consider-using-f-string
% (
Expand Down Expand Up @@ -143,7 +143,7 @@ def report(self, message): # pragma no cover


def parse_messages(cmdline=None):
"""Do a helper method to generate the messages to parse"""
"""Do a helper method to generate the messages to parse."""
args = get_commandline(cmdline=cmdline)
_logger.setLevel(args.log.upper())
if not args.message: # pragma no cover
Expand All @@ -163,7 +163,7 @@ def parse_messages(cmdline=None):


def main(cmdline=None):
"""Run program"""
"""Run program."""
parse_messages(cmdline=cmdline)


Expand Down
3 changes: 1 addition & 2 deletions examples/modbus_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

async def setup_forwarder(args):
"""Do setup forwarder."""

return args


Expand Down Expand Up @@ -66,7 +65,7 @@ async def run_forwarder(args):


async def async_helper():
"""Combine setup and run"""
"""Combine setup and run."""
cmd_args = helper.get_commandline(
server=True,
description="Run asynchronous forwarder.",
Expand Down
2 changes: 1 addition & 1 deletion examples/server_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class CallbackDataBlock(ModbusSequentialDataBlock):
"""A datablock that stores the new value in memory,
"""A datablock that stores the new value in memory,.
and passes the operation to a message queue for further processing.
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/server_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def setup(self):
)

async def run(self):
"""Attach Run server"""
"""Attach Run server."""
await self.server.serve_forever()


Expand Down
3 changes: 1 addition & 2 deletions examples/server_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

def setup_payload_server(cmdline=None):
"""Define payload for server and do setup."""

# ----------------------------------------------------------------------- #
# build your payload
# ----------------------------------------------------------------------- #
Expand Down Expand Up @@ -60,7 +59,7 @@ def setup_payload_server(cmdline=None):


async def main(cmdline=None):
"""Combine setup and run"""
"""Combine setup and run."""
run_args = setup_payload_server(cmdline=cmdline)
await server_async.run_async_server(run_args)

Expand Down
5 changes: 2 additions & 3 deletions examples/server_updating.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ async def updating_task(context):
It should be noted that getValues and setValues are not safe
against concurrent use.
"""

fc_as_hex = 3
slave_id = 0x00
address = 0x10
Expand Down Expand Up @@ -103,14 +102,14 @@ def setup_updating_server(cmdline=None):


async def run_updating_server(args):
"""Start updating_task concurrently with the current task"""
"""Start updating_task concurrently with the current task."""
task = asyncio.create_task(updating_task(args.context))
await server_async.run_async_server(args) # start the server
task.cancel()


async def main(cmdline=None):
"""Combine setup and run"""
"""Combine setup and run."""
run_args = setup_updating_server(cmdline=cmdline)
await run_updating_server(run_args)

Expand Down
1 change: 0 additions & 1 deletion examples/simple_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

async def run_async_simple_client(comm, host, port, framer=Framer.SOCKET):
"""Run async client."""

# activate debugging
pymodbus_apply_logging_config("DEBUG")

Expand Down
1 change: 0 additions & 1 deletion examples/simple_sync_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

def run_sync_simple_client(comm, host, port, framer=Framer.SOCKET):
"""Run sync client."""

# activate debugging
pymodbus_apply_logging_config("DEBUG")

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Client"""
"""Client."""

__all__ = [
"AsyncModbusSerialClient",
Expand Down
7 changes: 3 additions & 4 deletions pymodbus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class ModbusBaseClient(ModbusClientMixin, ModbusProtocol):
"""**ModbusBaseClient**
"""**ModbusBaseClient**.
Fixed parameters:
Expand Down Expand Up @@ -212,15 +212,15 @@ async def async_execute(self, request=None):
return resp

def callback_data(self, data: bytes, addr: tuple | None = None) -> int:
"""Handle received data
"""Handle received data.
returns number of bytes consumed
"""
self.framer.processIncomingPacket(data, self._handle_response, slave=0)
return len(data)

def callback_disconnected(self, _reason: Exception | None) -> None:
"""Handle lost connection"""
"""Handle lost connection."""
for tid in list(self.transaction):
self.raise_future(
self.transaction.getTransaction(tid),
Expand Down Expand Up @@ -292,7 +292,6 @@ def __enter__(self):
:returns: The current instance of the client
:raises ConnectionException:
"""

if not self.connect():
raise ConnectionException(f"Failed to connect[{self.__str__()}]")
return self
Expand Down
10 changes: 5 additions & 5 deletions pymodbus/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class ModbusStatus(int, enum.Enum):
SLAVE_OFF = 0x00

def __str__(self):
"""Override to force int representation for enum members"""
"""Override to force int representation for enum members."""
return str(int(self))


Expand Down Expand Up @@ -76,7 +76,7 @@ class Endian(str, enum.Enum):
LITTLE = "<"

def __str__(self):
"""Override to force str representation for enum members"""
"""Override to force str representation for enum members."""
return str.__str__(self)


Expand All @@ -98,7 +98,7 @@ class ModbusPlusOperation(int, enum.Enum):
CLEAR_STATISTICS = 0x0004

def __str__(self):
"""Override to force int representation for enum members"""
"""Override to force int representation for enum members."""
return str(int(self))


Expand Down Expand Up @@ -135,7 +135,7 @@ class DeviceInformation(int, enum.Enum):
SPECIFIC = 0x04

def __str__(self):
"""Override to force int representation for enum members"""
"""Override to force int representation for enum members."""
return str(int(self))


Expand All @@ -155,5 +155,5 @@ class MoreData(int, enum.Enum):
KEEP_READING = 0xFF

def __str__(self):
"""Override to force int representation for enum members"""
"""Override to force int representation for enum members."""
return str(int(self))
2 changes: 1 addition & 1 deletion pymodbus/datastore/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate(self, _fc_as_hex, _address, _count):
return True

def getValues(self, fc_as_hex, _address, _count=1):
"""Get values from real call in validate"""
"""Get values from real call in validate."""
if fc_as_hex in self._write_fc:
return [0]
group_fx = self.decode(fc_as_hex)
Expand Down
Loading

0 comments on commit 0108921

Please sign in to comment.