Skip to content

Add regression tests for RichText serialization across all three supported shapes - #2611

Closed
Badiboy with Copilot wants to merge 5 commits into
masterfrom
copilot/fix-code-review-comment
Closed

Add regression tests for RichText serialization across all three supported shapes#2611
Badiboy with Copilot wants to merge 5 commits into
masterfrom
copilot/fix-code-review-comment

Conversation

Copilot AI commented Aug 9, 2026

Copy link
Copy Markdown

RichText can be a plain string, a list, or a typed subclass — but no tests verified these shapes round-tripped correctly through InputRichMessage/InputRichBlock serialization. Subtypes with extra required fields (e.g. RichTextDateTime) were silently dropping those fields.

Changes

  • Merged RichText Dictionaryable support from PR Make RichText Dictionaryable #2610: adds to_dict() to all RichText subclasses and a RichText.richtext_to_dict() helper that dispatches across all three shapes; updates all InputRichBlock subclasses to use it instead of the direct .to_dict() call that broke on strings and lists.

  • Added regression tests in tests/test_types.py covering:

    • test_rich_text_plain_string_serialization — plain str through InputRichBlockParagraphInputRichMessage
    • test_rich_text_nested_list_serialization — mixed [str, RichTextBold] list
    • test_rich_text_nested_richtext_serialization — single RichTextBold object
    • test_rich_text_datetime_serializationRichTextDateTime asserting unix_time and date_time_format are present in output
# Previously would raise AttributeError or silently drop fields
dt = types.RichTextDateTime(text='Jan 1', unix_time=1740000000, date_time_format='short')
block = types.InputRichBlockParagraph(text=dt)
d = types.InputRichMessage(blocks=[block]).to_dict()
# Now correctly produces:
# {'blocks': [{'type': 'paragraph', 'text': {'type': 'date_time', 'text': 'Jan 1',
#              'unix_time': 1740000000, 'date_time_format': 'short'}}]}

Badiboy and others added 2 commits August 9, 2026 16:06
Make RichText Dictionaryable
Conform the fact that RichText can be str or list also.
Badiboy and others added 3 commits August 9, 2026 16:11
Co-authored-by: Badiboy <5613421+Badiboy@users.noreply.github.com>
… nested list, nested RichText, RichTextDateTime)

Co-authored-by: Badiboy <5613421+Badiboy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code according to review comment Add regression tests for RichText serialization across all three supported shapes Aug 9, 2026
Copilot AI requested a review from Badiboy August 9, 2026 13:17
@Badiboy
Badiboy requested a balanced review from Copilot August 12, 2026 14:16
@Badiboy Badiboy closed this Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds serialization support and regression coverage for all supported RichText shapes.

Changes:

  • Adds recursive RichText dictionary serialization.
  • Updates rich block serialization to handle strings, lists, and typed objects.
  • Adds regression tests for key shapes and date-time fields.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
telebot/types.py Implements RichText and rich block serialization.
tests/test_types.py Covers supported serialization shapes.
Suppressed comments (1)

telebot/types.py:14798

  • Unsupported values, including an invalid element nested inside a list, are silently converted to None. This turns programmer errors into malformed null fields in the outgoing payload; fail fast with TypeError instead.
        return None

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread telebot/types.py
return data

@staticmethod
def richtext_to_dict(richtext: Union[str, List[RichText], RichText]):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants