From d2e244817aa4d5ac21469038cd529e3f3163365d Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 5 Oct 2017 12:28:04 +0200 Subject: [PATCH] Make EntityDatabase.get a no-op if key is an entity already --- telethon/tl/entity_database.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/telethon/tl/entity_database.py b/telethon/tl/entity_database.py index 50a4207e..94528cfd 100644 --- a/telethon/tl/entity_database.py +++ b/telethon/tl/entity_database.py @@ -117,8 +117,14 @@ class EntityDatabase: if isinstance(key, int): return self._entities[key] # normal IDs are assumed users - if isinstance(key, TLObject) and type(key).SUBCLASS_OF_ID == 0x2d45687: - return self._entities[utils.get_peer_id(key, add_mark=True)] + if isinstance(key, TLObject): + sc = type(key).SUBCLASS_OF_ID + if sc == 0x2d45687: + # Subclass of "Peer" + return self._entities[utils.get_peer_id(key, add_mark=True)] + elif sc in {0x2da17977, 0xc5af5d94, 0x6d44b7db}: + # Subclass of "User", "Chat" or "Channel" + return key raise KeyError(key)