Skip to content

Commit e752b6d

Browse files
authored
Expand mypy config, following HomeAssistant (#1392)
1 parent 77cecde commit e752b6d

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

pymodbus/device.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,6 @@ class ModbusControlBlock:
456456

457457
__mode = "ASCII"
458458
__diagnostic = [False] * 16
459-
__instance = None
460459
__listen_only = False
461460
__delimiter = "\r"
462461
__counters = ModbusCountersHandler()

pymodbus/repl/client/helper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# pylint: disable=missing-type-doc
55
import json
66
from collections import OrderedDict
7+
from typing import Any, Dict, List, Union
78

89
import pygments
910
from prompt_toolkit import print_formatted_text
@@ -58,7 +59,7 @@
5859
"set_timeout",
5960
"get_serial_settings",
6061
]
61-
CLIENT_ATTRIBUTES = []
62+
CLIENT_ATTRIBUTES: List[str] = []
6263

6364

6465
class Command:
@@ -230,8 +231,8 @@ def get_commands(client):
230231
class Result:
231232
"""Represent result command."""
232233

233-
function_code = None
234-
data = None
234+
function_code: int = None
235+
data: Union[Dict[int, Any], Any] = None
235236

236237
def __init__(self, result):
237238
"""Initialize.

pymodbus/server/async_io.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ssl
55
import time
66
import traceback
7+
from typing import Union
78

89
from pymodbus.client.serial_asyncio import create_serial_connection
910
from pymodbus.constants import Defaults
@@ -873,7 +874,7 @@ class ModbusSerialServer: # pylint: disable=too-many-instance-attributes
873874
server context instance.
874875
"""
875876

876-
handler = None
877+
handler: ModbusSingleRequestHandler = None
877878

878879
def __init__(
879880
self, context, framer=ModbusRtuFramer, identity=None, **kwargs
@@ -1052,7 +1053,9 @@ class _serverList:
10521053
:meta private:
10531054
"""
10541055

1055-
active_server = None
1056+
active_server: Union[
1057+
ModbusUnixServer, ModbusTcpServer, ModbusUdpServer, ModbusSerialServer
1058+
] = None
10561059

10571060
def __init__(self, server):
10581061
"""Register new server."""

pymodbus/server/reactive/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import threading
1111
import time
1212
from enum import Enum
13+
from typing import Union
1314

1415

1516
try:
@@ -396,7 +397,7 @@ def create_identity(
396397
def create_context(
397398
cls,
398399
data_block_settings: dict = {},
399-
unit: list[int] = [1],
400+
unit: Union[list[int]] | int = [1],
400401
single: bool = False,
401402
randomize: int = 0,
402403
change_rate: int = 0,

setup.cfg

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,29 @@ noqa-require-code = True
503503

504504
[mypy]
505505
strict_optional = False
506-
exclude = pymodbus/client/base.py
506+
exclude = pymodbus/client/base.py
507+
508+
# below are those used in HomeAssistant
509+
show_error_codes = true
510+
# follow_imports = silent
511+
# ignore_missing_imports = true
512+
local_partial_types = true
513+
strict_equality = true
514+
warn_incomplete_stub = true
515+
warn_redundant_casts = true
516+
warn_unused_configs = true
517+
warn_unused_ignores = true
518+
enable_error_code = ignore-without-code, redundant-self, truthy-iterable
519+
disable_error_code = annotation-unchecked
520+
strict_concatenate = false
521+
# check_untyped_defs = true
522+
# disallow_incomplete_defs = true
523+
disallow_subclassing_any = true
524+
# disallow_untyped_calls = true
525+
disallow_untyped_decorators = true
526+
# disallow_untyped_defs = true
527+
# warn_return_any = true
528+
warn_unreachable = true
507529

508530

509531
[egg_info]

0 commit comments

Comments
 (0)