Skip to content

Commit 808440d

Browse files
committed
Add public generic type vars
This is to make documentation more readable, and to be able to document those type variables. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 63c8dc0 commit 808440d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/frequenz/channels/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
from ._anycast import Anycast
7878
from ._broadcast import Broadcast
7979
from ._exceptions import ChannelClosedError, ChannelError, Error
80+
from ._generic import (
81+
ChannelMessageT,
82+
ErroredChannelT_co,
83+
MappedMessageT_co,
84+
ReceiverMessageT_co,
85+
SenderMessageT_co,
86+
SenderMessageT_contra,
87+
)
8088
from ._merge import Merger, merge
8189
from ._receiver import Receiver, ReceiverError, ReceiverStoppedError
8290
from ._select import (
@@ -93,15 +101,21 @@
93101
"Broadcast",
94102
"ChannelClosedError",
95103
"ChannelError",
104+
"ChannelMessageT",
96105
"Error",
106+
"ErroredChannelT_co",
107+
"MappedMessageT_co",
97108
"Merger",
98109
"Receiver",
99110
"ReceiverError",
111+
"ReceiverMessageT_co",
100112
"ReceiverStoppedError",
101113
"SelectError",
102114
"Selected",
103115
"Sender",
104116
"SenderError",
117+
"SenderMessageT_co",
118+
"SenderMessageT_contra",
105119
"UnhandledSelectedError",
106120
"merge",
107121
"select",

src/frequenz/channels/_generic.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# License: MIT
2+
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Generic type variables."""
5+
6+
from typing import TypeVar
7+
8+
ChannelMessageT = TypeVar("ChannelMessageT")
9+
"""The type of the message that can be sent across a channel."""
10+
11+
ErroredChannelT_co = TypeVar("ErroredChannelT_co", covariant=True)
12+
"""The type of channel having an error."""
13+
14+
MappedMessageT_co = TypeVar("MappedMessageT_co", covariant=True)
15+
"""The type of the message received by the receiver after being mapped."""
16+
17+
ReceiverMessageT_co = TypeVar("ReceiverMessageT_co", covariant=True)
18+
"""The type of the message received by a receiver."""
19+
20+
SenderMessageT_co = TypeVar("SenderMessageT_co", covariant=True)
21+
"""The type of the message sent by a sender."""
22+
23+
SenderMessageT_contra = TypeVar("SenderMessageT_contra", contravariant=True)
24+
"""The type of the message sent by a sender."""

0 commit comments

Comments
 (0)