Skip to content

Update a test and some formatting fixes #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 17 additions & 22 deletions telegram/_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2533,20 +2533,20 @@ def _parse_html(
elif entity.type == MessageEntity.URL and urled:
insert = f'<a href="{text}">{text}</a>'
elif entity.type == MessageEntity.BOLD:
insert = '<b>' + text + '</b>'
insert = f'<b>{text}</b>'
elif entity.type == MessageEntity.ITALIC:
insert = '<i>' + text + '</i>'
insert = f'<i>{text}</i>'
elif entity.type == MessageEntity.CODE:
insert = '<code>' + text + '</code>'
insert = f'<code>{text}</code>'
elif entity.type == MessageEntity.PRE:
if entity.language:
insert = f'<pre><code class="{entity.language}">{text}</code></pre>'
else:
insert = '<pre>' + text + '</pre>'
insert = f'<pre>{text}</pre>'
elif entity.type == MessageEntity.UNDERLINE:
insert = '<u>' + text + '</u>'
insert = f'<u>{text}</u>'
elif entity.type == MessageEntity.STRIKETHROUGH:
insert = '<s>' + text + '</s>'
insert = f'<s>{text}</s>'
elif entity.type == MessageEntity.SPOILER:
insert = f'<span class="tg-spoiler">{text}</span>'
else:
Expand Down Expand Up @@ -2697,7 +2697,7 @@ def _parse_markdown(
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(
Expand Down Expand Up @@ -2726,43 +2726,38 @@ def _parse_markdown(
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(
Expand Down
6 changes: 4 additions & 2 deletions telegram/ext/_contexttypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]):
"""
Expand Down
8 changes: 4 additions & 4 deletions tests/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,13 +615,13 @@ def test_idle(self, updater, caplog):
# (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

Expand Down