From f1371c3999c8936434f08c0ff774d3e9fb9e7528 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sat, 20 Jan 2018 19:39:48 +0100 Subject: [PATCH] Early return from Session.get_input_entity() if Input* given --- telethon/session.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/telethon/session.py b/telethon/session.py index f7170478..21c0e105 100644 --- a/telethon/session.py +++ b/telethon/session.py @@ -401,12 +401,16 @@ class Session: Raises ValueError if it cannot be found. """ - if isinstance(key, TLObject): - try: - # Try to early return if this key can be casted as input peer - return utils.get_input_peer(key) - except TypeError: - # Otherwise, get the ID of the peer + try: + if key.SUBCLASS_OF_ID in (0xc91c90b6, 0xe669bf46, 0x40f202fd): + # hex(crc32(b'InputPeer', b'InputUser' and b'InputChannel')) + # We already have an Input version, so nothing else required + return key + # Try to early return if this key can be casted as input peer + return utils.get_input_peer(key) + except (AttributeError, TypeError): + # Not a TLObject or can't be cast into InputPeer + if isinstance(key, TLObject): key = utils.get_peer_id(key) c = self._conn.cursor()