Skip to content

Fix RichText - #2615

Merged
Badiboy merged 2 commits into
eternnoir:masterfrom
Badiboy:master
Aug 15, 2026
Merged

Fix RichText#2615
Badiboy merged 2 commits into
eternnoir:masterfrom
Badiboy:master

Conversation

@Badiboy

@Badiboy Badiboy commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

Description

  1. It's now ABC
  2. de_json with json-string was lost. Now it processes string under some heuristics.

1. It's now ABC

2. de_json with json-string was lost. Now it processes string under some heuristics.
@Badiboy
Badiboy requested a lite review from Copilot August 15, 2026 20:36
@Badiboy

Badiboy commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

@coder2020official - please, take a fast look. Update is small.

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

This PR updates the rich-text deserialization layer in telebot/types.py, aiming to (1) formalize base rich-text types as abstract bases and (2) restore support for passing JSON-encoded strings into de_json via heuristics.

Changes:

  • Make RichText and RichBlock inherit from ABC.
  • Update RichText.de_json to treat some str inputs as JSON and parse them instead of always returning the raw string.
Suppressed comments (1)

telebot/types.py:14743

  • RichText.de_json currently treats any valid JSON string as structured rich text, but it then calls check_json() and assumes the result is a dict (uses obj.pop). For inputs like '"hello"' or '[]' (valid JSON that parses to str/list), check_json() returns a non-dict and this will raise at obj.pop. Also, this file optionally aliases ujson as json (types.py:12-16), so referencing json.JSONDecodeError can fail if ujson doesn't expose that exception type.
            try:
                # Check if string is valid json. If so, assume it's json, not plain string
                json.loads(json_string)
                # If it's valid json, continue to json processing below
            except (ValueError, TypeError, json.JSONDecodeError):

💡 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
Comment on lines 14735 to 14736
@@ -14736,8 +14736,14 @@ def de_json(cls, json_string):
if json_string is None: return None
"123" is also a valid json :(

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

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

Comment thread telebot/types.py
Comment on lines +14739 to +14748
if (json_string.startswith('{') and json_string.endswith('}')) or (json_string.startswith('[') and json_string.endswith(']')):
try:
# Check if string is valid json. If so, assume it's json, not plain string
json.loads(json_string)
# If it's valid json, continue to json processing below
except (ValueError, TypeError, json.JSONDecodeError):
# If it's not valid json, return the string as is
return json_string
else:
return json_string
@Badiboy
Badiboy merged commit 55a165b into eternnoir:master Aug 15, 2026
6 checks passed
@Badiboy

Badiboy commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Damn, I include wrong files in last fix and did not noticed that... 🙈🙈🙈

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