Skip to content

Commit

Permalink
Fix custom parse_mode instances (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-a-xD authored Feb 2, 2024
1 parent 70201a9 commit 41eb665
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions telethon/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,17 @@ 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):
raise NotImplementedError

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 {
Expand Down

0 comments on commit 41eb665

Please sign in to comment.