Skip to content

Commit

Permalink
pylint and pre-commit autoupdate (#1519)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbraza authored Apr 25, 2023
1 parent abbe99a commit 487d2dd
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 32 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
# run ruff with --fix before black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
rev: 'v0.0.263'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.3.0
hooks:
- id: black
args: [--safe, --quiet]
Expand Down
4 changes: 2 additions & 2 deletions examples/build_bcd_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ def build(self):
"""
string = str(self)
length = len(string)
string = string + ("\x00" * (length % 2))
string += "\x00" * (length % 2)
return [string[i : i + 2] for i in range(0, length, 2)]

def add_bits(self, values: int) -> int:
def add_bits(self, values: int) -> None:
"""Add a collection of bits to be encoded
If these are less than a multiple of eight,
Expand Down
2 changes: 1 addition & 1 deletion examples/message_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def report(self, message):
message.__class__.__name__,
)
)
for (k_dict, v_dict) in message.__dict__.items():
for k_dict, v_dict in message.__dict__.items():
if isinstance(v_dict, dict):
print("%-15s =" % k_dict) # pylint: disable=consider-using-f-string
for k_item, v_item in v_dict.items():
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/serial_asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def _call_connection_lost(self, exc):
if self._serial:
try:
self._serial.flush()
except (serial.SerialException if os.name == "nt" else termios.error):
except serial.SerialException if os.name == "nt" else termios.error:
# ignore serial errors which may happen if the serial device was
# hot-unplugged.
pass
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/client/sync_diag.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
self.warn_delay_limit = self.params.timeout / 2

# Set logging messages, defaulting to LOG_MSGS
for (k_item, v_item) in LOG_MSGS.items():
for k_item, v_item in LOG_MSGS.items():
self.__dict__[k_item] = kwargs.get(k_item, v_item)

def connect(self):
Expand Down
6 changes: 3 additions & 3 deletions pymodbus/datastore/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def validate(self, fc_as_hex, address, count=1):
:returns: True if the request in within range, False otherwise
"""
if not self.zero_mode:
address = address + 1
address += 1
Log.debug("validate: fc-[{}] address-{}: count-{}", fc_as_hex, address, count)
return self.store[self.decode(fc_as_hex)].validate(address, count)

Expand All @@ -89,7 +89,7 @@ def getValues(self, fc_as_hex, address, count=1):
:returns: The requested values from a:a+c
"""
if not self.zero_mode:
address = address + 1
address += 1
Log.debug("getValues: fc-[{}] address-{}: count-{}", fc_as_hex, address, count)
return self.store[self.decode(fc_as_hex)].getValues(address, count)

Expand All @@ -101,7 +101,7 @@ def setValues(self, fc_as_hex, address, values):
:param values: The new values to be set
"""
if not self.zero_mode:
address = address + 1
address += 1
Log.debug("setValues[{}] address-{}: count-{}", fc_as_hex, address, len(values))
self.store[self.decode(fc_as_hex)].setValues(address, values)

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/diag_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def decode(self, data):
word_len = len(data) // 2
if len(data) % 2:
word_len += 1
data = data + b"0"
data += b"0"
data = struct.unpack(">" + "H" * word_len, data)
(
self.sub_function_code, # pylint: disable=attribute-defined-outside-init
Expand Down
2 changes: 1 addition & 1 deletion pymodbus/mei_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def encode(self):
self.space_left = 253 - 6
objects = b""
try:
for (object_id, data) in iter(self.information.items()):
for object_id, data in iter(self.information.items()):
if isinstance(data, list):
for item in data:
objects += self._encode_object(object_id, item)
Expand Down
8 changes: 2 additions & 6 deletions pymodbus/other_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,13 +475,9 @@ def decode(self, data):
status = int(data[-1])
self.status = status == ModbusStatus.SlaveOn

def __str__(self):
def __str__(self) -> str:
"""Build a representation of the response.
:returns: The string representation of the response
"""
arguments = (self.function_code, self.identifier, self.status)
return (
"ReportSlaveIdResponse(%s, %s, %s)" # pylint: disable=consider-using-f-string
% arguments
)
return f"ReportSlaveIdResponse({self.function_code}, {self.identifier}, {self.status})"
2 changes: 1 addition & 1 deletion pymodbus/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def build(self):
"""
string = self.to_string()
length = len(string)
string = string + (b"\x00" * (length % 2))
string += b"\x00" * (length % 2)
return [string[i : i + 2] for i in range(0, length, 2)]

def add_bits(self, values):
Expand Down
6 changes: 1 addition & 5 deletions pymodbus/repl/client/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ def convert(self, value, param, ctx):
return choice

self.fail(
"invalid choice: %s. (choose from %s)" # pylint: disable=consider-using-f-string
% (
value,
", ".join(self.choices),
),
f"invalid choice: {value}. (choose from {', '.join(self.choices)})",
param,
ctx,
)
Expand Down
4 changes: 2 additions & 2 deletions pymodbus/server/reactive/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def getValues(self, fc_as_hex, address, count=1):
:returns: The requested values from a:a+c
"""
if not self.zero_mode:
address = address + 1
address += 1
Log.debug("getValues: fc-[{}] address-{}: count-{}", fc_as_hex, address, count)
_block_type = self.decode(fc_as_hex)
if self._randomize > 0 and _block_type in {"d", "i"}:
Expand Down Expand Up @@ -215,7 +215,7 @@ def __init__(self, host, port, modbus_server):
self._add_routes()
self._counter = 0
self._modbus_server.response_manipulator = self.manipulate_response
self._manipulator_config = dict(**DEFAULT_MANIPULATOR)
self._manipulator_config = {**DEFAULT_MANIPULATOR}
self._web_app.on_startup.append(self.start_modbus_server)
self._web_app.on_shutdown.append(self.stop_modbus_server)

Expand Down
2 changes: 1 addition & 1 deletion pymodbus/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def execute(self, request): # noqa: C901
if hasattr(request, "get_response_pdu_size"):
response_pdu_size = request.get_response_pdu_size()
if isinstance(self.client.framer, ModbusAsciiFramer):
response_pdu_size = response_pdu_size * 2
response_pdu_size *= 2
if response_pdu_size:
expected_response_length = (
self._calculate_response_length(response_pdu_size)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pre-commit==3.1.1
pyflakes==3.0.1
pydocstyle==6.3.0
pycodestyle==2.10.0
pylint==2.15.10
pylint==2.17.2
pytest==7.2.1
pytest-asyncio==0.20.3
pytest-cov==4.0.0
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ deprecated-modules=regsub,TERMIOS,Bastion,rexec
[pylint.exceptions]

# Exceptions that will emit a warning when being caught.
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception

[pylint.deprecated_builtins]

Expand Down
2 changes: 0 additions & 2 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ async def test_client_modbusbaseclient():
) as p_connect, mock.patch(
"pymodbus.client.base.ModbusBaseClient.close"
) as p_close:

p_connect.return_value = True
p_close.return_value = True
with ModbusBaseClient(framer=ModbusAsciiFramer) as b_client:
Expand Down Expand Up @@ -330,7 +329,6 @@ async def test_client_base_async():
) as p_connect, mock.patch(
"pymodbus.client.base.ModbusBaseClient.close"
) as p_close:

loop = asyncio.get_event_loop()
p_connect.return_value = loop.create_future()
p_connect.return_value.set_result(True)
Expand Down

0 comments on commit 487d2dd

Please sign in to comment.