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 {