Skip to content

Commit 7a843fb

Browse files
Add pipe docstring (#2868)
Co-authored-by: Chester Chen <[email protected]>
1 parent 2bb6e27 commit 7a843fb

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

nvflare/fuel/utils/pipe/pipe.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Message:
3838
def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=None):
3939
check_str("msg_type", msg_type)
4040
if msg_type not in [Message.REPLY, Message.REQUEST]:
41-
raise ValueError(f"invalid note_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}")
41+
raise ValueError(f"invalid msg_type '{msg_type}': must be one of {[Message.REPLY, Message.REQUEST]}")
4242
self.msg_type = msg_type
4343

4444
check_str("topic", topic)
@@ -61,10 +61,46 @@ def __init__(self, msg_type: str, topic: str, data: Any, msg_id=None, req_id=Non
6161

6262
@staticmethod
6363
def new_request(topic: str, data: Any, msg_id=None):
64+
"""Creates a new request message.
65+
66+
This static method creates a new `Message` object representing a request.
67+
68+
Args:
69+
topic (str): The topic of the request message.
70+
This is a string that identifies the subject or category of the request.
71+
data (Any): The data associated with the request message.
72+
This can be any type of data that is relevant to the request.
73+
msg_id (Optional[Any]): An optional identifier for the message.
74+
If provided, this ID is used to uniquely identify the message.
75+
If not provided, a UUID will be generated to uniquely identify the message.
76+
77+
Returns:
78+
Message: A `Message` object with the type set to `Message.REQUEST`,
79+
and the provided `topic`, `data`, and `msg_id`.
80+
81+
"""
6482
return Message(Message.REQUEST, topic, data, msg_id)
6583

6684
@staticmethod
6785
def new_reply(topic: str, data: Any, req_msg_id, msg_id=None):
86+
"""Creates a new reply message in response to a request.
87+
88+
This static method creates a new `Message` object representing a reply to a previous request.
89+
90+
Args:
91+
topic (str): The topic of the reply message.
92+
This is a string that identifies the subject or category of the reply.
93+
data (Any): The data associated with the reply message. This can be any type of data relevant to the reply.
94+
req_msg_id (int): The identifier of the request message that this reply is responding to.
95+
This ID links the reply to the original request.
96+
msg_id (Optional[int]): An optional identifier for the reply message.
97+
If provided, this ID is used to uniquely identify the message.
98+
If not provided, a UUID will be generated to uniquely identify the message.
99+
100+
Returns:
101+
Message: A `Message` object with the type set to `Message.REPLY`,
102+
and the provided `topic`, `data`, `msg_id`, and `req_msg_id`.
103+
"""
68104
return Message(Message.REPLY, topic, data, msg_id, req_id=req_msg_id)
69105

70106
def __str__(self):

0 commit comments

Comments
 (0)