From 001a067d82e9b31bfe853837371f49b2971cba96 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 15 Dec 2018 09:50:35 +0100 Subject: [PATCH] Make start and stop methods return self to make chaining possible Suggestion by @CharlesBachman in Telegram --- pyrogram/client/client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 2094eb9c..9235eb12 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -198,10 +198,9 @@ class Client(Methods, BaseClient): self.dispatcher = Dispatcher(self, workers) def __enter__(self): - self.start() - return self + return self.start() - def __exit__(self, exc_type, exc_val, exc_tb): + def __exit__(self, *args): self.stop() @property @@ -294,6 +293,8 @@ class Client(Methods, BaseClient): mimetypes.init() Syncer.add(self) + return self + def stop(self): """Use this method to manually stop the Client. Requires no parameters. @@ -331,6 +332,8 @@ class Client(Methods, BaseClient): self.is_started = False self.session.stop() + return self + def idle(self, stop_signals: tuple = (SIGINT, SIGTERM, SIGABRT)): """Blocks the program execution until one of the signals are received, then gently stop the Client by closing the underlying connection.