Skip to content

Commit bd9bb83

Browse files
committed
Reword some methods' docstring
1 parent 5914991 commit bd9bb83

File tree

1 file changed

+62
-36
lines changed

1 file changed

+62
-36
lines changed

pyrogram/client/client.py

Lines changed: 62 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,7 @@ def proxy(self, value):
261261
self._proxy.update(value)
262262

263263
def start(self):
264-
"""Use this method to start the Client after creating it.
265-
Requires no parameters.
264+
"""Use this method to start the Client.
266265
267266
Raises:
268267
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
@@ -355,8 +354,7 @@ def start(self):
355354
return self
356355

357356
def stop(self):
358-
"""Use this method to manually stop the Client.
359-
Requires no parameters.
357+
"""Use this method to stop the Client.
360358
361359
Raises:
362360
``ConnectionError`` in case you try to stop an already stopped Client.
@@ -399,7 +397,6 @@ def stop(self):
399397

400398
def restart(self):
401399
"""Use this method to restart the Client.
402-
Requires no parameters.
403400
404401
Raises:
405402
``ConnectionError`` in case you try to restart a stopped Client.
@@ -408,15 +405,25 @@ def restart(self):
408405
self.start()
409406

410407
def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)):
411-
"""Blocks the program execution until one of the signals are received,
412-
then gently stop the Client by closing the underlying connection.
408+
"""Use this method to block the main script execution until a signal (e.g.: from CTRL+C) is received.
409+
Once the signal is received, the client will automatically stop and the main script will continue its execution.
410+
411+
This is used after starting one or more clients and is useful for event-driven applications only, that are,
412+
applications which react upon incoming Telegram updates through handlers, rather than executing a set of methods
413+
sequentially.
414+
415+
The way Pyrogram works, will keep your handlers in a pool of workers, which are executed concurrently outside
416+
the main script; calling idle() will ensure the client(s) will be kept alive by not letting the main script to
417+
end, until you decide to quit.
413418
414419
Args:
415420
stop_signals (``tuple``, *optional*):
416421
Iterable containing signals the signal handler will listen to.
417422
Defaults to (SIGINT, SIGTERM, SIGABRT).
418423
"""
419424

425+
# TODO: Maybe make this method static and don't automatically stop
426+
420427
def signal_handler(*args):
421428
self.is_idle = False
422429

@@ -431,8 +438,11 @@ def signal_handler(*args):
431438
self.stop()
432439

433440
def run(self):
434-
"""Use this method to automatically start and idle a Client.
435-
Requires no parameters.
441+
"""Use this method as a convenience shortcut to automatically start the Client and idle the main script.
442+
443+
This is a convenience method that literally just calls :meth:`start` and :meth:`idle`. It makes running a client
444+
less verbose, but is not suitable in case you want to run more than one client in a single main script,
445+
since :meth:`idle` will block.
436446
437447
Raises:
438448
:class:`RPCError <pyrogram.RPCError>` in case of a Telegram RPC error.
@@ -465,7 +475,7 @@ def add_handler(self, handler: Handler, group: int = 0):
465475
return handler, group
466476

467477
def remove_handler(self, handler: Handler, group: int = 0):
468-
"""Removes a previously-added update handler.
478+
"""Use this method to remove a previously-registered update handler.
469479
470480
Make sure to provide the right group that the handler was added in. You can use
471481
the return value of the :meth:`add_handler` method, a tuple of (handler, group), and
@@ -752,9 +762,16 @@ def default_recovery_callback(email_pattern: str) -> str:
752762

753763
print("Logged in successfully as {}".format(r.user.first_name))
754764

755-
def fetch_peers(self, entities: List[Union[types.User,
756-
types.Chat, types.ChatForbidden,
757-
types.Channel, types.ChannelForbidden]]):
765+
def fetch_peers(
766+
self,
767+
entities: List[
768+
Union[
769+
types.User,
770+
types.Chat, types.ChatForbidden,
771+
types.Channel, types.ChannelForbidden
772+
]
773+
]
774+
):
758775
for entity in entities:
759776
if isinstance(entity, types.User):
760777
user_id = entity.id
@@ -1018,16 +1035,19 @@ def updates_worker(self):
10181035

10191036
log.debug("{} stopped".format(name))
10201037

1021-
def send(self,
1022-
data: Object,
1023-
retries: int = Session.MAX_RETRIES,
1024-
timeout: float = Session.WAIT_TIMEOUT):
1025-
"""Use this method to send Raw Function queries.
1038+
def send(self, data: Object, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT):
1039+
"""Use this method to send raw Telegram queries.
10261040
1027-
This method makes possible to manually call every single Telegram API method in a low-level manner.
1041+
This method makes it possible to manually call every single Telegram API method in a low-level manner.
10281042
Available functions are listed in the :obj:`functions <pyrogram.api.functions>` package and may accept compound
10291043
data types from :obj:`types <pyrogram.api.types>` as well as bare types such as ``int``, ``str``, etc...
10301044
1045+
.. note::
1046+
1047+
This is a utility method intended to be used **only** when working with raw
1048+
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
1049+
available yet in the Client class as an easy-to-use method).
1050+
10311051
Args:
10321052
data (``Object``):
10331053
The API Schema function filled with proper arguments.
@@ -1285,8 +1305,7 @@ def save_session(self):
12851305
indent=4
12861306
)
12871307

1288-
def get_initial_dialogs_chunk(self,
1289-
offset_date: int = 0):
1308+
def get_initial_dialogs_chunk(self, offset_date: int = 0):
12901309
while True:
12911310
try:
12921311
r = self.send(
@@ -1318,13 +1337,15 @@ def get_initial_dialogs(self):
13181337

13191338
self.get_initial_dialogs_chunk()
13201339

1321-
def resolve_peer(self,
1322-
peer_id: Union[int, str]):
1323-
"""Use this method to get the InputPeer of a known peer_id.
1340+
def resolve_peer(self, peer_id: Union[int, str]):
1341+
"""Use this method to get the InputPeer of a known peer id.
1342+
Useful whenever an InputPeer type is required.
1343+
1344+
.. note::
13241345
1325-
This is a utility method intended to be used **only** when working with Raw Functions (i.e: a Telegram API
1326-
method you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an
1327-
InputPeer type is required.
1346+
This is a utility method intended to be used **only** when working with raw
1347+
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
1348+
available yet in the Client class as an easy-to-use method).
13281349
13291350
Args:
13301351
peer_id (``int`` | ``str``):
@@ -1391,17 +1412,22 @@ def resolve_peer(self,
13911412
except KeyError:
13921413
raise PeerIdInvalid
13931414

1394-
def save_file(self,
1395-
path: str,
1396-
file_id: int = None,
1397-
file_part: int = 0,
1398-
progress: callable = None,
1399-
progress_args: tuple = ()):
1415+
def save_file(
1416+
self,
1417+
path: str,
1418+
file_id: int = None,
1419+
file_part: int = 0,
1420+
progress: callable = None,
1421+
progress_args: tuple = ()
1422+
):
14001423
"""Use this method to upload a file onto Telegram servers, without actually sending the message to anyone.
1424+
Useful whenever an InputFile type is required.
1425+
1426+
.. note::
14011427
1402-
This is a utility method intended to be used **only** when working with Raw Functions (i.e: a Telegram API
1403-
method you wish to use which is not available yet in the Client class as an easy-to-use method), whenever an
1404-
InputFile type is required.
1428+
This is a utility method intended to be used **only** when working with raw
1429+
:obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
1430+
available yet in the Client class as an easy-to-use method).
14051431
14061432
Args:
14071433
path (``str``):

0 commit comments

Comments
 (0)