diff --git a/tqdm/contrib/telegram.py b/tqdm/contrib/telegram.py index 72c9619a..f2b3bcf0 100644 --- a/tqdm/contrib/telegram.py +++ b/tqdm/contrib/telegram.py @@ -63,17 +63,15 @@ class TelegramIO(MonoWorker): return future def delete(self): + """Deletes internal `message_id`.""" try: - res = self.submit( - self.session.post, - self.API + '%s/deleteMessage' % self.token, - data=dict( - chat_id=self.chat_id, - message_id=self.message_id)) + future = self.submit( + self.session.post, self.API + '%s/deleteMessage' % self.token, + data={'chat_id': self.chat_id, 'message_id': self.message_id}) except Exception as e: tqdm_auto.write(str(e)) else: - return res + return future class tqdm_telegram(tqdm_auto): @@ -125,8 +123,12 @@ class tqdm_telegram(tqdm_auto): if not self.disable: self.tgio.write("") - def delete(self): - self.tgio.delete() + def close(self): + if self.disable: + return + super(tqdm_telegram, self).close() + if not (self.leave or (self.leave is None and self.pos == 0)): + self.tgio.delete() def ttgrange(*args, **kwargs): diff --git a/tqdm/rich.py b/tqdm/rich.py index 0ad6545a..2bbe384c 100644 --- a/tqdm/rich.py +++ b/tqdm/rich.py @@ -113,10 +113,10 @@ class tqdm_rich(std_tqdm): # pragma: no cover self._prog.__enter__() self._task_id = self._prog.add_task(self.desc or "", **d) - def close(self, *args, **kwargs): + def close(self): if self.disable: return - super(tqdm_rich, self).close(*args, **kwargs) + super(tqdm_rich, self).close() self._prog.__exit__(None, None, None) def clear(self, *_, **__):