Skip to content

Commit b1c5768

Browse files
committed
Eliminate final (!) implicit optional
1 parent 0909c37 commit b1c5768

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

pymodbus/transport/transport.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ def __init__(
156156
self.is_server = is_server
157157
self.is_closing = False
158158

159-
self.transport: asyncio.BaseTransport = None
160-
self.loop: asyncio.AbstractEventLoop = None
159+
self.transport: asyncio.BaseTransport | None = None
160+
self.loop: asyncio.AbstractEventLoop
161161
self.recv_buffer: bytes = b""
162162
self.call_create: Callable[[], Coroutine[Any, Any, Any]] = lambda: None
163163
if self.is_server:
@@ -240,8 +240,7 @@ def init_setup_connect_listen(self, host: str, port: int) -> None:
240240
async def transport_connect(self) -> bool:
241241
"""Handle generic connect and call on to specific transport connect."""
242242
Log.debug("Connecting {}", self.comm_params.comm_name)
243-
if not self.loop:
244-
self.loop = asyncio.get_running_loop()
243+
self.loop = asyncio.get_running_loop()
245244
self.is_closing = False
246245
try:
247246
self.transport, _protocol = await asyncio.wait_for(
@@ -260,12 +259,11 @@ async def transport_connect(self) -> bool:
260259
async def transport_listen(self) -> bool:
261260
"""Handle generic listen and call on to specific transport listen."""
262261
Log.debug("Awaiting connections {}", self.comm_params.comm_name)
263-
if not self.loop:
264-
self.loop = asyncio.get_running_loop()
262+
self.loop = asyncio.get_running_loop()
265263
self.is_closing = False
266264
try:
267265
self.transport = await self.call_create()
268-
if isinstance(self.transport, tuple):
266+
if self.transport and isinstance(self.transport, tuple):
269267
self.transport = self.transport[0]
270268
except OSError as exc:
271269
Log.warning("Failed to start server {}", exc)
@@ -395,11 +393,11 @@ def transport_send(self, data: bytes, addr: tuple | None = None) -> None:
395393
self.sent_buffer += data
396394
if self.comm_params.comm_type == CommType.UDP:
397395
if addr:
398-
self.transport.sendto(data, addr=addr) # type: ignore[attr-defined]
396+
self.transport.sendto(data, addr=addr) # type: ignore[union-attr]
399397
else:
400-
self.transport.sendto(data) # type: ignore[attr-defined]
398+
self.transport.sendto(data) # type: ignore[union-attr]
401399
else:
402-
self.transport.write(data) # type: ignore[attr-defined]
400+
self.transport.write(data) # type: ignore[union-attr]
403401

404402
def transport_close(self, intern: bool = False, reconnect: bool = False) -> None:
405403
"""Close connection.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ overgeneral-exceptions = "builtins.Exception"
187187
bad-functions = "map,input"
188188

189189
[tool.mypy]
190-
strict_optional = false
190+
strict_optional = true
191191
show_error_codes = true
192192
local_partial_types = true
193193
strict_equality = true

0 commit comments

Comments
 (0)