Skip to content

Commit 9c7a135

Browse files
committed
Replace "chan" with "channel"
This is just for consistency and extra clarity. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 5a8d9dc commit 9c7a135

File tree

3 files changed

+52
-52
lines changed

3 files changed

+52
-52
lines changed

src/frequenz/channels/_anycast.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ class _Sender(Sender[_T]):
309309
method.
310310
"""
311311

312-
def __init__(self, chan: Anycast[_T]) -> None:
312+
def __init__(self, channel: Anycast[_T]) -> None:
313313
"""Initialize this sender.
314314
315315
Args:
316-
chan: A reference to the channel that this sender belongs to.
316+
channel: A reference to the channel that this sender belongs to.
317317
"""
318-
self._chan: Anycast[_T] = chan
318+
self._channel: Anycast[_T] = channel
319319
"""The channel that this sender belongs to."""
320320

321321
async def send(self, message: _T) -> None:
@@ -335,35 +335,35 @@ async def send(self, message: _T) -> None:
335335
set as the cause.
336336
"""
337337
# pylint: disable=protected-access
338-
if self._chan._closed:
338+
if self._channel._closed:
339339
raise SenderError("The channel was closed", self) from ChannelClosedError(
340-
self._chan
340+
self._channel
341341
)
342-
if len(self._chan._deque) == self._chan._deque.maxlen:
342+
if len(self._channel._deque) == self._channel._deque.maxlen:
343343
_logger.warning(
344344
"Anycast channel [%s] is full, blocking sender until a receiver "
345345
"consumes a message",
346346
self,
347347
)
348-
while len(self._chan._deque) == self._chan._deque.maxlen:
349-
async with self._chan._send_cv:
350-
await self._chan._send_cv.wait()
348+
while len(self._channel._deque) == self._channel._deque.maxlen:
349+
async with self._channel._send_cv:
350+
await self._channel._send_cv.wait()
351351
_logger.info(
352352
"Anycast channel [%s] has space again, resuming the blocked sender",
353353
self,
354354
)
355-
self._chan._deque.append(message)
356-
async with self._chan._recv_cv:
357-
self._chan._recv_cv.notify(1)
355+
self._channel._deque.append(message)
356+
async with self._channel._recv_cv:
357+
self._channel._recv_cv.notify(1)
358358
# pylint: enable=protected-access
359359

360360
def __str__(self) -> str:
361361
"""Return a string representation of this sender."""
362-
return f"{self._chan}:{type(self).__name__}"
362+
return f"{self._channel}:{type(self).__name__}"
363363

364364
def __repr__(self) -> str:
365365
"""Return a string representation of this sender."""
366-
return f"{type(self).__name__}({self._chan!r})"
366+
return f"{type(self).__name__}({self._channel!r})"
367367

368368

369369
class _Empty:
@@ -377,13 +377,13 @@ class _Receiver(Receiver[_T]):
377377
method.
378378
"""
379379

380-
def __init__(self, chan: Anycast[_T]) -> None:
380+
def __init__(self, channel: Anycast[_T]) -> None:
381381
"""Initialize this receiver.
382382
383383
Args:
384-
chan: A reference to the channel that this receiver belongs to.
384+
channel: A reference to the channel that this receiver belongs to.
385385
"""
386-
self._chan: Anycast[_T] = chan
386+
self._channel: Anycast[_T] = channel
387387
"""The channel that this receiver belongs to."""
388388

389389
self._next: _T | type[_Empty] = _Empty
@@ -404,14 +404,14 @@ async def ready(self) -> bool:
404404
return True
405405

406406
# pylint: disable=protected-access
407-
while len(self._chan._deque) == 0:
408-
if self._chan._closed:
407+
while len(self._channel._deque) == 0:
408+
if self._channel._closed:
409409
return False
410-
async with self._chan._recv_cv:
411-
await self._chan._recv_cv.wait()
412-
self._next = self._chan._deque.popleft()
413-
async with self._chan._send_cv:
414-
self._chan._send_cv.notify(1)
410+
async with self._channel._recv_cv:
411+
await self._channel._recv_cv.wait()
412+
self._next = self._channel._deque.popleft()
413+
async with self._channel._send_cv:
414+
self._channel._send_cv.notify(1)
415415
# pylint: enable=protected-access
416416
return True
417417

@@ -426,9 +426,9 @@ def consume(self) -> _T:
426426
ReceiverError: If there is some problem with the receiver.
427427
"""
428428
if ( # pylint: disable=protected-access
429-
self._next is _Empty and self._chan._closed
429+
self._next is _Empty and self._channel._closed
430430
):
431-
raise ReceiverStoppedError(self) from ChannelClosedError(self._chan)
431+
raise ReceiverStoppedError(self) from ChannelClosedError(self._channel)
432432

433433
assert (
434434
self._next is not _Empty
@@ -442,8 +442,8 @@ def consume(self) -> _T:
442442

443443
def __str__(self) -> str:
444444
"""Return a string representation of this receiver."""
445-
return f"{self._chan}:{type(self).__name__}"
445+
return f"{self._channel}:{type(self).__name__}"
446446

447447
def __repr__(self) -> str:
448448
"""Return a string representation of this receiver."""
449-
return f"{type(self).__name__}({self._chan!r})"
449+
return f"{type(self).__name__}({self._channel!r})"

src/frequenz/channels/_broadcast.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,13 @@ class _Sender(Sender[_T]):
308308
method.
309309
"""
310310

311-
def __init__(self, chan: Broadcast[_T]) -> None:
311+
def __init__(self, channel: Broadcast[_T]) -> None:
312312
"""Initialize this sender.
313313
314314
Args:
315-
chan: A reference to the broadcast channel this sender belongs to.
315+
channel: A reference to the broadcast channel this sender belongs to.
316316
"""
317-
self._chan: Broadcast[_T] = chan
317+
self._channel: Broadcast[_T] = channel
318318
"""The broadcast channel this sender belongs to."""
319319

320320
async def send(self, message: _T) -> None:
@@ -329,31 +329,31 @@ async def send(self, message: _T) -> None:
329329
set as the cause.
330330
"""
331331
# pylint: disable=protected-access
332-
if self._chan._closed:
332+
if self._channel._closed:
333333
raise SenderError("The channel was closed", self) from ChannelClosedError(
334-
self._chan
334+
self._channel
335335
)
336-
self._chan._latest = message
336+
self._channel._latest = message
337337
stale_refs = []
338-
for _hash, recv_ref in self._chan._receivers.items():
338+
for _hash, recv_ref in self._channel._receivers.items():
339339
recv = recv_ref()
340340
if recv is None:
341341
stale_refs.append(_hash)
342342
continue
343343
recv.enqueue(message)
344344
for _hash in stale_refs:
345-
del self._chan._receivers[_hash]
346-
async with self._chan._recv_cv:
347-
self._chan._recv_cv.notify_all()
345+
del self._channel._receivers[_hash]
346+
async with self._channel._recv_cv:
347+
self._channel._recv_cv.notify_all()
348348
# pylint: enable=protected-access
349349

350350
def __str__(self) -> str:
351351
"""Return a string representation of this sender."""
352-
return f"{self._chan}:{type(self).__name__}"
352+
return f"{self._channel}:{type(self).__name__}"
353353

354354
def __repr__(self) -> str:
355355
"""Return a string representation of this sender."""
356-
return f"{type(self).__name__}({self._chan!r})"
356+
return f"{type(self).__name__}({self._channel!r})"
357357

358358

359359
class _Receiver(Receiver[_T]):
@@ -364,7 +364,7 @@ class _Receiver(Receiver[_T]):
364364
method.
365365
"""
366366

367-
def __init__(self, name: str | None, limit: int, chan: Broadcast[_T]) -> None:
367+
def __init__(self, name: str | None, limit: int, channel: Broadcast[_T]) -> None:
368368
"""Initialize this receiver.
369369
370370
Broadcast receivers have their own buffer, and when messages are not
@@ -377,7 +377,7 @@ def __init__(self, name: str | None, limit: int, chan: Broadcast[_T]) -> None:
377377
purposes, it will be shown in the string representation of the
378378
receiver.
379379
limit: Number of messages the receiver can hold in its buffer.
380-
chan: a reference to the Broadcast channel that this receiver
380+
channel: a reference to the Broadcast channel that this receiver
381381
belongs to.
382382
"""
383383
self._name: str = name if name is not None else f"{id(self):_}"
@@ -386,7 +386,7 @@ def __init__(self, name: str | None, limit: int, chan: Broadcast[_T]) -> None:
386386
Only used for debugging purposes.
387387
"""
388388

389-
self._chan: Broadcast[_T] = chan
389+
self._channel: Broadcast[_T] = channel
390390
"""The broadcast channel that this receiver belongs to."""
391391

392392
self._q: deque[_T] = deque(maxlen=limit)
@@ -439,10 +439,10 @@ async def ready(self) -> bool:
439439
# consumed, then we return immediately.
440440
# pylint: disable=protected-access
441441
while len(self._q) == 0:
442-
if self._chan._closed:
442+
if self._channel._closed:
443443
return False
444-
async with self._chan._recv_cv:
445-
await self._chan._recv_cv.wait()
444+
async with self._channel._recv_cv:
445+
await self._channel._recv_cv.wait()
446446
return True
447447
# pylint: enable=protected-access
448448

@@ -455,21 +455,21 @@ def consume(self) -> _T:
455455
Raises:
456456
ReceiverStoppedError: If there is some problem with the receiver.
457457
"""
458-
if not self._q and self._chan._closed: # pylint: disable=protected-access
459-
raise ReceiverStoppedError(self) from ChannelClosedError(self._chan)
458+
if not self._q and self._channel._closed: # pylint: disable=protected-access
459+
raise ReceiverStoppedError(self) from ChannelClosedError(self._channel)
460460

461461
assert self._q, "`consume()` must be preceded by a call to `ready()`"
462462
return self._q.popleft()
463463

464464
def __str__(self) -> str:
465465
"""Return a string representation of this receiver."""
466-
return f"{self._chan}:{type(self).__name__}"
466+
return f"{self._channel}:{type(self).__name__}"
467467

468468
def __repr__(self) -> str:
469469
"""Return a string representation of this receiver."""
470470
limit = self._q.maxlen
471471
assert limit is not None
472472
return (
473473
f"{type(self).__name__}(name={self._name!r}, limit={limit!r}, "
474-
f"{self._chan!r}):<id={id(self)!r}, used={len(self._q)!r}>"
474+
f"{self._channel!r}):<id={id(self)!r}, used={len(self._q)!r}>"
475475
)

src/frequenz/channels/_merge.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def merge(*receivers: Receiver[_T]) -> Merger[_T]:
7070
```python
7171
from frequenz.channels import Broadcast
7272
73-
channel1 = Broadcast[int](name="input-chan-1")
74-
channel2 = Broadcast[int](name="input-chan-2")
73+
channel1 = Broadcast[int](name="input-channel-1")
74+
channel2 = Broadcast[int](name="input-channel-2")
7575
receiver1 = channel1.new_receiver()
7676
receiver2 = channel2.new_receiver()
7777

0 commit comments

Comments
 (0)