Skip to content

Commit 5a8d9dc

Browse files
committed
Replace "msg" with "message"
This is just to make the code extra obvious but it also affects one function signature: `Sender.send()`, so it is a breaking change. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent bd7b04e commit 5a8d9dc

File tree

6 files changed

+40
-40
lines changed

6 files changed

+40
-40
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ async def main() -> None:
7676
receiver = hello_channel.new_receiver()
7777

7878
await sender.send("Hello World!")
79-
msg = await receiver.receive()
80-
print(msg)
79+
message = await receiver.receive()
80+
print(message)
8181

8282

8383
asyncio.run(main())

docs/user-guide/receiving/synchronization/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ not work:
99
receiver1: Receiver[int] = channel1.new_receiver()
1010
receiver2: Receiver[int] = channel2.new_receiver()
1111

12-
msg = await receiver1.receive()
13-
print(f"Received from channel1: {msg}")
12+
message = await receiver1.receive()
13+
print(f"Received from channel1: {message}")
1414

15-
msg = await receiver2.receive()
16-
print(f"Received from channel2: {msg}")
15+
message = await receiver2.receive()
16+
print(f"Received from channel2: {message}")
1717
```
1818

1919
The problem is that if the first message is not available in `channel1` but in

src/frequenz/channels/_anycast.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ class Anycast(Generic[_T]):
101101
102102
103103
async def send(sender: Sender[int]) -> None:
104-
for msg in range(3):
105-
print(f"sending {msg}")
106-
await sender.send(msg)
104+
for message in range(3):
105+
print(f"sending {message}")
106+
await sender.send(message)
107107
108108
109109
async def main() -> None:
@@ -115,8 +115,8 @@ async def main() -> None:
115115
async with asyncio.TaskGroup() as task_group:
116116
task_group.create_task(send(sender))
117117
for _ in range(3):
118-
msg = await receiver.receive()
119-
print(f"received {msg}")
118+
message = await receiver.receive()
119+
print(f"received {message}")
120120
await asyncio.sleep(0.1) # sleep (or work) with the data
121121
122122
@@ -146,15 +146,15 @@ async def main() -> None:
146146
147147
148148
async def send(name: str, sender: Sender[int], start: int, stop: int) -> None:
149-
for msg in range(start, stop):
150-
print(f"{name} sending {msg}")
151-
await sender.send(msg)
149+
for message in range(start, stop):
150+
print(f"{name} sending {message}")
151+
await sender.send(message)
152152
153153
154154
async def recv(name: str, receiver: Receiver[int]) -> None:
155155
try:
156-
async for msg in receiver:
157-
print(f"{name} received {msg}")
156+
async for message in receiver:
157+
print(f"{name} received {message}")
158158
await asyncio.sleep(0.1) # sleep (or work) with the data
159159
except ReceiverStoppedError:
160160
pass
@@ -318,7 +318,7 @@ def __init__(self, chan: Anycast[_T]) -> None:
318318
self._chan: Anycast[_T] = chan
319319
"""The channel that this sender belongs to."""
320320

321-
async def send(self, msg: _T) -> None:
321+
async def send(self, message: _T) -> None:
322322
"""Send a message across the channel.
323323
324324
To send, this method inserts the message into the Anycast channel's
@@ -327,7 +327,7 @@ async def send(self, msg: _T) -> None:
327327
message will be received by exactly one receiver.
328328
329329
Args:
330-
msg: The message to be sent.
330+
message: The message to be sent.
331331
332332
Raises:
333333
SenderError: If the underlying channel was closed.
@@ -352,7 +352,7 @@ async def send(self, msg: _T) -> None:
352352
"Anycast channel [%s] has space again, resuming the blocked sender",
353353
self,
354354
)
355-
self._chan._deque.append(msg)
355+
self._chan._deque.append(message)
356356
async with self._chan._recv_cv:
357357
self._chan._recv_cv.notify(1)
358358
# pylint: enable=protected-access

src/frequenz/channels/_broadcast.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class Broadcast(Generic[_T]):
8989
9090
9191
async def send(sender: Sender[int]) -> None:
92-
for msg in range(3):
93-
print(f"sending {msg}")
94-
await sender.send(msg)
92+
for message in range(3):
93+
print(f"sending {message}")
94+
await sender.send(message)
9595
9696
9797
async def main() -> None:
@@ -103,8 +103,8 @@ async def main() -> None:
103103
async with asyncio.TaskGroup() as task_group:
104104
task_group.create_task(send(sender))
105105
for _ in range(3):
106-
msg = await receiver.receive()
107-
print(f"received {msg}")
106+
message = await receiver.receive()
107+
print(f"received {message}")
108108
await asyncio.sleep(0.1) # sleep (or work) with the data
109109
110110
@@ -134,15 +134,15 @@ async def main() -> None:
134134
135135
136136
async def send(name: str, sender: Sender[int], start: int, stop: int) -> None:
137-
for msg in range(start, stop):
138-
print(f"{name} sending {msg}")
139-
await sender.send(msg)
137+
for message in range(start, stop):
138+
print(f"{name} sending {message}")
139+
await sender.send(message)
140140
141141
142142
async def recv(name: str, receiver: Receiver[int]) -> None:
143143
try:
144-
async for msg in receiver:
145-
print(f"{name} received {msg}")
144+
async for message in receiver:
145+
print(f"{name} received {message}")
146146
await asyncio.sleep(0.1) # sleep (or work) with the data
147147
except ReceiverStoppedError:
148148
pass
@@ -317,11 +317,11 @@ def __init__(self, chan: Broadcast[_T]) -> None:
317317
self._chan: Broadcast[_T] = chan
318318
"""The broadcast channel this sender belongs to."""
319319

320-
async def send(self, msg: _T) -> None:
320+
async def send(self, message: _T) -> None:
321321
"""Send a message to all broadcast receivers.
322322
323323
Args:
324-
msg: The message to be broadcast.
324+
message: The message to be broadcast.
325325
326326
Raises:
327327
SenderError: If the underlying channel was closed.
@@ -333,14 +333,14 @@ async def send(self, msg: _T) -> None:
333333
raise SenderError("The channel was closed", self) from ChannelClosedError(
334334
self._chan
335335
)
336-
self._chan._latest = msg
336+
self._chan._latest = message
337337
stale_refs = []
338338
for _hash, recv_ref in self._chan._receivers.items():
339339
recv = recv_ref()
340340
if recv is None:
341341
stale_refs.append(_hash)
342342
continue
343-
recv.enqueue(msg)
343+
recv.enqueue(message)
344344
for _hash in stale_refs:
345345
del self._chan._receivers[_hash]
346346
async with self._chan._recv_cv:
@@ -392,23 +392,23 @@ def __init__(self, name: str | None, limit: int, chan: Broadcast[_T]) -> None:
392392
self._q: deque[_T] = deque(maxlen=limit)
393393
"""The receiver's internal message queue."""
394394

395-
def enqueue(self, msg: _T) -> None:
395+
def enqueue(self, message: _T) -> None:
396396
"""Put a message into this receiver's queue.
397397
398398
To be called by broadcast senders. If the receiver's queue is already
399399
full, drop the oldest message to make room for the incoming message, and
400400
log a warning.
401401
402402
Args:
403-
msg: The message to be sent.
403+
message: The message to be sent.
404404
"""
405405
if len(self._q) == self._q.maxlen:
406406
self._q.popleft()
407407
_logger.warning(
408408
"Broadcast receiver [%s] is full. Oldest message was dropped.",
409409
self,
410410
)
411-
self._q.append(msg)
411+
self._q.append(message)
412412

413413
def __len__(self) -> int:
414414
"""Return the number of unconsumed messages in the broadcast receiver.

src/frequenz/channels/_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ def merge(*receivers: Receiver[_T]) -> Merger[_T]:
7575
receiver1 = channel1.new_receiver()
7676
receiver2 = channel2.new_receiver()
7777
78-
async for msg in merge(receiver1, receiver2):
79-
print(f"received {msg}")
78+
async for message in merge(receiver1, receiver2):
79+
print(f"received {message}")
8080
```
8181
8282
Args:

src/frequenz/channels/_sender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class Sender(ABC, Generic[_T_contra]):
6161
"""An endpoint to sends messages."""
6262

6363
@abstractmethod
64-
async def send(self, msg: _T_contra) -> None:
64+
async def send(self, message: _T_contra) -> None:
6565
"""Send a message.
6666
6767
Args:
68-
msg: The message to be sent.
68+
message: The message to be sent.
6969
7070
Raises:
7171
SenderError: If there was an error sending the message.

0 commit comments

Comments
 (0)