Closed
Add regression tests for RichText serialization across all three supported shapes#2611
Conversation
Make RichText Dictionaryable Conform the fact that RichText can be str or list also.
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
Contributor
There was a problem hiding this comment.
Pull request overview
Adds serialization support and regression coverage for all supported RichText shapes.
Changes:
- Adds recursive
RichTextdictionary 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 malformednullfields in the outgoing payload; fail fast withTypeErrorinstead.
return None
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| return data | ||
|
|
||
| @staticmethod | ||
| def richtext_to_dict(richtext: Union[str, List[RichText], RichText]): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RichTextcan be a plain string, a list, or a typed subclass — but no tests verified these shapes round-tripped correctly throughInputRichMessage/InputRichBlockserialization. Subtypes with extra required fields (e.g.RichTextDateTime) were silently dropping those fields.Changes
Merged
RichTextDictionaryable support from PR Make RichText Dictionaryable #2610: addsto_dict()to allRichTextsubclasses and aRichText.richtext_to_dict()helper that dispatches across all three shapes; updates allInputRichBlocksubclasses to use it instead of the direct.to_dict()call that broke on strings and lists.Added regression tests in
tests/test_types.pycovering:test_rich_text_plain_string_serialization— plainstrthroughInputRichBlockParagraph→InputRichMessagetest_rich_text_nested_list_serialization— mixed[str, RichTextBold]listtest_rich_text_nested_richtext_serialization— singleRichTextBoldobjecttest_rich_text_datetime_serialization—RichTextDateTimeassertingunix_timeanddate_time_formatare present in output