From 41eb665c9d5c440372d0a5c49e3b9df99563b322 Mon Sep 17 00:00:00 2001 From: Just-a-xD <96680394+Just-a-xD@users.noreply.github.com> Date: Fri, 2 Feb 2024 22:46:01 +0530 Subject: [PATCH] Fix custom parse_mode instances (#4304) --- telethon/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/telethon/utils.py b/telethon/utils.py index ab78d8a4..1c939e98 100644 --- a/telethon/utils.py +++ b/telethon/utils.py @@ -756,7 +756,10 @@ def sanitize_parse_mode(mode): if not mode: return None - if callable(mode): + if (all(hasattr(mode, x) for x in ('parse', 'unparse')) + and all(callable(x) for x in (mode.parse, mode.unparse))): + return mode + elif callable(mode): class CustomMode: @staticmethod def unparse(text, entities): @@ -764,9 +767,6 @@ def sanitize_parse_mode(mode): CustomMode.parse = mode return CustomMode - elif (all(hasattr(mode, x) for x in ('parse', 'unparse')) - and all(callable(x) for x in (mode.parse, mode.unparse))): - return mode elif isinstance(mode, str): try: return {