diff --git a/telegram/_message.py b/telegram/_message.py index 8157fd89c..dc11d377b 100644 --- a/telegram/_message.py +++ b/telegram/_message.py @@ -2533,20 +2533,20 @@ class Message(TelegramObject): elif entity.type == MessageEntity.URL and urled: insert = f'{text}' elif entity.type == MessageEntity.BOLD: - insert = '' + text + '' + insert = f'{text}' elif entity.type == MessageEntity.ITALIC: - insert = '' + text + '' + insert = f'{text}' elif entity.type == MessageEntity.CODE: - insert = '' + text + '' + insert = f'{text}' elif entity.type == MessageEntity.PRE: if entity.language: insert = f'
{text}
' else: - insert = '
' + text + '
' + insert = f'
{text}
' elif entity.type == MessageEntity.UNDERLINE: - insert = '' + text + '' + insert = f'{text}' elif entity.type == MessageEntity.STRIKETHROUGH: - insert = '' + text + '' + insert = f'{text}' elif entity.type == MessageEntity.SPOILER: insert = f'{text}' else: @@ -2697,7 +2697,7 @@ class Message(TelegramObject): if nested_entities: if version < 2: raise ValueError( - 'Nested entities are not supported for Markdown ' 'version 1' + 'Nested entities are not supported for Markdown version 1' ) text = Message._parse_markdown( @@ -2726,43 +2726,38 @@ class Message(TelegramObject): link = text insert = f'[{link}]({orig_text})' elif entity.type == MessageEntity.BOLD: - insert = '*' + text + '*' + insert = f'*{text}*' elif entity.type == MessageEntity.ITALIC: - insert = '_' + text + '_' + insert = f'_{text}_' elif entity.type == MessageEntity.CODE: # Monospace needs special escaping. Also can't have entities nested within - insert = ( - '`' - + escape_markdown( - orig_text, version=version, entity_type=MessageEntity.CODE - ) - + '`' - ) + insert = f'`{escape_markdown(orig_text, version, MessageEntity.CODE)}`' + elif entity.type == MessageEntity.PRE: # Monospace needs special escaping. Also can't have entities nested within code = escape_markdown( orig_text, version=version, entity_type=MessageEntity.PRE ) if entity.language: - prefix = '```' + entity.language + '\n' + prefix = f'```{entity.language}\n' else: if code.startswith('\\'): prefix = '```' else: prefix = '```\n' - insert = prefix + code + '```' + insert = f'{prefix}{code}```' elif entity.type == MessageEntity.UNDERLINE: if version == 1: raise ValueError( - 'Underline entities are not supported for Markdown ' 'version 1' + 'Underline entities are not supported for Markdown version 1' ) - insert = '__' + text + '__' + insert = f'__{text}__' elif entity.type == MessageEntity.STRIKETHROUGH: if version == 1: raise ValueError( - 'Strikethrough entities are not supported for Markdown ' 'version 1' + 'Strikethrough entities are not supported for Markdown version 1' ) - insert = '~' + text + '~' + insert = f'~{text}~' elif entity.type == MessageEntity.SPOILER: if version == 1: raise ValueError( diff --git a/telegram/ext/_contexttypes.py b/telegram/ext/_contexttypes.py index 9819d23f3..bc4bfe55b 100644 --- a/telegram/ext/_contexttypes.py +++ b/telegram/ext/_contexttypes.py @@ -18,12 +18,14 @@ # along with this program. If not, see [http://www.gnu.org/licenses/]. # pylint: disable=no-self-use """This module contains the auxiliary class ContextTypes.""" -from typing import Type, Generic, overload, Dict # pylint: disable=unused-import +from typing import Type, Generic, overload, Dict, TYPE_CHECKING # pylint: disable=unused-import from telegram.ext._callbackcontext import CallbackContext -from telegram.ext._extbot import ExtBot # pylint: disable=unused-import from telegram.ext._utils.types import CCT, UD, CD, BD +if TYPE_CHECKING: + from telegram.ext._extbot import ExtBot # pylint: disable=unused-import + class ContextTypes(Generic[CCT, UD, CD, BD]): """ diff --git a/tests/test_updater.py b/tests/test_updater.py index 6d1912899..3e7920d04 100644 --- a/tests/test_updater.py +++ b/tests/test_updater.py @@ -615,13 +615,13 @@ class TestUpdater: # (bots) running simultaneously while testing in github actions. records = caplog.records.copy() # To avoid iterating and removing at same time for idx, log in enumerate(records): - print(log) + print(idx, log) msg = log.getMessage() if msg.startswith('Error while getting Updates: Conflict'): - caplog.records.pop(idx) # For stability + caplog.records.remove(log) # For stability - if msg.startswith('No error handlers are registered'): - caplog.records.pop(idx) + elif msg.startswith('No error handlers are registered'): + caplog.records.remove(log) assert len(caplog.records) == 2, caplog.records