Skip to content

Commit e1572e9

Browse files
authored
Merge branch 'develop' into bugfix/blf-reader-missing-direction-of-can-fd
2 parents 98416f3 + b4f5da9 commit e1572e9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

can/interfaces/virtual.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515
from threading import RLock
1616
from random import randint
1717

18-
from can import CanError
18+
from can import CanOperationError
1919
from can.bus import BusABC
2020
from can.message import Message
21+
from can.typechecking import AutoDetectedConfig
2122

2223
logger = logging.getLogger(__name__)
2324

2425

2526
# Channels are lists of queues, one for each connection
2627
if TYPE_CHECKING:
27-
# https://mypy.readthedocs.io/en/stable/common_issues.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
28+
# https://mypy.readthedocs.io/en/stable/runtime_troubles.html#using-classes-that-are-generic-in-stubs-but-not-at-runtime
2829
channels: Dict[Optional[Any], List[queue.Queue[Message]]] = {}
2930
else:
3031
channels = {}
@@ -58,7 +59,7 @@ def __init__(
5859
channel: Any = None,
5960
receive_own_messages: bool = False,
6061
rx_queue_size: int = 0,
61-
**kwargs: Any
62+
**kwargs: Any,
6263
) -> None:
6364
super().__init__(
6465
channel=channel, receive_own_messages=receive_own_messages, **kwargs
@@ -81,12 +82,12 @@ def __init__(
8182
self.channel.append(self.queue)
8283

8384
def _check_if_open(self) -> None:
84-
"""Raises CanError if the bus is not open.
85+
"""Raises :class:`~can.CanOperationError` if the bus is not open.
8586
8687
Has to be called in every method that accesses the bus.
8788
"""
8889
if not self._open:
89-
raise CanError("Operation on closed bus")
90+
raise CanOperationError("Cannot operate on a closed bus")
9091

9192
def _recv_internal(
9293
self, timeout: Optional[float]
@@ -116,8 +117,9 @@ def send(self, msg: Message, timeout: Optional[float] = None) -> None:
116117
bus_queue.put(msg_copy, block=True, timeout=timeout)
117118
except queue.Full:
118119
all_sent = False
120+
119121
if not all_sent:
120-
raise CanError("Could not send message to one or more recipients")
122+
raise CanOperationError("Could not send message to one or more recipients")
121123

122124
def shutdown(self) -> None:
123125
if self._open:
@@ -131,7 +133,7 @@ def shutdown(self) -> None:
131133
del channels[self.channel_id]
132134

133135
@staticmethod
134-
def _detect_available_configs():
136+
def _detect_available_configs() -> List[AutoDetectedConfig]:
135137
"""
136138
Returns all currently used channels as well as
137139
one other currently unused channel.
@@ -146,7 +148,9 @@ def _detect_available_configs():
146148
available_channels = list(channels.keys())
147149

148150
# find a currently unused channel
149-
get_extra = lambda: "channel-{}".format(randint(0, 9999))
151+
def get_extra():
152+
return f"channel-{randint(0, 9999)}"
153+
150154
extra = get_extra()
151155
while extra in available_channels:
152156
extra = get_extra()

0 commit comments

Comments
 (0)