Skip to content

Commit b4f3aa1

Browse files
Michael GravesMichael Graves
authored andcommitted
Fixed general linting issues
1 parent f2a3f30 commit b4f3aa1

2 files changed

Lines changed: 27 additions & 31 deletions

File tree

can/notifier.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@
1010
from collections.abc import Awaitable, Callable, Iterable
1111
from contextlib import AbstractContextManager
1212
from types import TracebackType
13-
from typing import (
14-
Any,
15-
Final,
16-
NamedTuple,
17-
)
13+
from typing import Any, Final, NamedTuple
1814

1915
from can.bus import BusABC
2016
from can.listener import Listener
@@ -101,7 +97,6 @@ def find_instances(self, bus: BusABC) -> tuple["Notifier", ...]:
10197

10298

10399
class Notifier(AbstractContextManager["Notifier"]):
104-
105100
_registry: Final = _NotifierRegistry()
106101

107102
def __init__(
@@ -316,20 +311,20 @@ def find_instances(bus: BusABC) -> tuple["Notifier", ...]:
316311

317312
def restart(self) -> None:
318313
"""Restarts the Notifier if it has been stopped.
319-
314+
320315
:raises RuntimeWarning: If the notifier is already running.
321316
"""
322317
with self._lock:
323318
if not self._stopped:
324319
raise RuntimeWarning("Notifier is already running.")
325-
320+
326321
self._stopped = False
327322
self.exception = None
328323
# Note: _bus_list is preserved from previous run
329-
324+
330325
for bus in self._bus_list:
331326
self._start_reader(bus)
332-
327+
333328
# Re-trigger listeners if they have a start method
334329
for listener in self.listeners:
335330
if hasattr(listener, "start"):

test/notifier_test.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,46 +76,46 @@ def test_restart(self):
7676
with can.Bus("test", interface="virtual", receive_own_messages=True) as bus:
7777
reader = can.BufferedReader()
7878
notifier = can.Notifier(bus, [reader], 0.1)
79-
79+
8080
bus.send(can.Message(arbitration_id=0x123))
8181
self.assertIsNotNone(reader.get_message(1))
82-
82+
8383
notifier.stop()
8484
self.assertTrue(notifier.stopped)
85-
85+
8686
new_reader = can.BufferedReader()
8787
notifier.listeners = [new_reader]
88-
88+
8989
notifier.restart()
9090
self.assertFalse(notifier.stopped)
91-
91+
9292
# Small settling time for the thread to actually start
9393
time.sleep(0.2)
94-
94+
9595
# Send and Verify
9696
msg = can.Message(arbitration_id=0xABC)
9797
bus.send(msg)
98-
98+
9999
recv = new_reader.get_message(1)
100100
self.assertIsNotNone(recv, "Failed to receive message after restart")
101101
self.assertEqual(recv.arbitration_id, 0xABC)
102-
102+
103103
notifier.stop()
104104

105105
def test_restart_registry_lifecycle(self):
106106
with can.Bus("test", interface="virtual", receive_own_messages=True) as bus:
107107
notifier = can.Notifier(bus, [], 0.1)
108108
notifier.stop()
109-
109+
110110
# Verify it is removed from registry
111111
self.assertEqual(can.Notifier.find_instances(bus), ())
112-
112+
113113
notifier.restart()
114-
114+
115115
# Verify it is back in the registry and blocking others
116116
self.assertEqual(can.Notifier.find_instances(bus), (notifier,))
117117
self.assertRaises(ValueError, can.Notifier, bus, [], 0.1)
118-
118+
119119
notifier.stop()
120120

121121
def test_double_restart_warning(self):
@@ -125,6 +125,7 @@ def test_double_restart_warning(self):
125125
with self.assertRaises(RuntimeWarning):
126126
notifier.restart()
127127

128+
128129
class AsyncNotifierTest(unittest.TestCase):
129130
def test_asyncio_notifier(self):
130131
async def run_it():
@@ -147,25 +148,25 @@ async def run_it():
147148
notifier = can.Notifier(
148149
bus, [reader], 0.1, loop=asyncio.get_running_loop()
149150
)
150-
151+
151152
notifier.stop()
152-
153+
153154
# In some cases, creating a new listener is the safest path for a restart
154155
new_reader = can.AsyncBufferedReader()
155-
notifier.listeners = [new_reader]
156-
156+
notifier.listeners = [new_reader]
157+
157158
notifier.restart()
158-
159+
159160
# Small yield to let the selector register the FD
160161
await asyncio.sleep(0.1)
161-
162+
162163
bus.send(can.Message(arbitration_id=0x123))
163-
164+
164165
recv_msg = await asyncio.wait_for(new_reader.get_message(), 1.5)
165-
166+
166167
self.assertIsNotNone(recv_msg)
167168
self.assertEqual(recv_msg.arbitration_id, 0x123)
168-
169+
169170
notifier.stop()
170171

171172
asyncio.run(run_it())

0 commit comments

Comments
 (0)