Fix custom parse_mode instances (#4304)

This commit is contained in:
Just-a-xD 2024-02-02 22:46:01 +05:30 committed by GitHub
parent 70201a9ff1
commit 41eb665c9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {