From 1609efbfbc8e54115b70c19940aa3d92ccf96d7e Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 27 Oct 2019 09:53:40 +0100 Subject: [PATCH] Add .bind() method to re-enable bound-methods after deserialization --- pyrogram/client/types/object.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pyrogram/client/types/object.py b/pyrogram/client/types/object.py index 5978203f..d51a8325 100644 --- a/pyrogram/client/types/object.py +++ b/pyrogram/client/types/object.py @@ -32,8 +32,15 @@ class Object(metaclass=Meta): def __init__(self, client: "pyrogram.BaseClient" = None): self._client = client - if self._client is None: - del self._client + def bind(self, client: "pyrogram.BaseClient"): + """Bind a Client instance to this Pyrogram Object + + Parameters: + client (:obj:`Client`): + The Client instance to bind this object with. Useful to re-enable bound methods after serializing and + deserializing Pyrogram objects with ``repr`` and ``eval``. + """ + self._client = client @staticmethod def default(obj: "Object"):