Recursively bind when using Object.bind()

This commit is contained in:
Dan 2022-04-24 11:56:07 +02:00
parent 5c0806a8a9
commit 6eadb75086

View File

@ -29,7 +29,7 @@ class Object:
self._client = client self._client = client
def bind(self, client: "pyrogram.Client"): def bind(self, client: "pyrogram.Client"):
"""Bind a Client instance to this Pyrogram Object """Recursively bind a Client instance to this and to all nested Pyrogram objects.
Parameters: Parameters:
client (:obj:`~pyrogram.types.Client`): client (:obj:`~pyrogram.types.Client`):
@ -38,6 +38,12 @@ class Object:
""" """
self._client = client self._client = client
for i in self.__dict__:
o = getattr(self, i)
if isinstance(o, Object):
o.bind(client)
@staticmethod @staticmethod
def default(obj: "Object"): def default(obj: "Object"):
if isinstance(obj, bytes): if isinstance(obj, bytes):