Skip to content

MessageID, InlineQueryResultBase changed as in API - #2618

Merged
Badiboy merged 13 commits into
eternnoir:masterfrom
Badiboy:master
Aug 18, 2026
Merged

MessageID, InlineQueryResultBase changed as in API#2618
Badiboy merged 13 commits into
eternnoir:masterfrom
Badiboy:master

Conversation

@Badiboy

@Badiboy Badiboy commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Description

MessageID left as deprecated for compatibility.

MaybeInaccessibleMessage added obviously as Union to conform API.

MessageID left as deprecated for compatibility.

MaybeInaccessibleMessage added obviously as Union to conform API.

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

Renames MessageID to API-aligned MessageId while retaining a deprecated compatibility class.

Changes:

  • Updates synchronous and asynchronous return types.
  • Adds MaybeInaccessibleMessage union.
  • Updates type tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
telebot/types.py Adds renamed and compatibility types.
telebot/__init__.py Uses MessageId in synchronous APIs.
telebot/async_telebot.py Uses MessageId in asynchronous APIs.
tests/test_types.py Tests MessageId deserialization.

💡 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 Outdated
Comment thread tests/test_types.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Badiboy Badiboy changed the title MessageID changed to MessageId as in API. MessageID, InlineQueryResultBase changed as in API Aug 16, 2026
@Badiboy
Badiboy requested a balanced review from Copilot August 16, 2026 11:35

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 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (3)

telebot/types.py:972

  • MessageID is retained as a subclass of the new type, but results now created as MessageId are not instances of MessageID. For example, the updated copy_message return path breaks existing isinstance(result, types.MessageID) checks, so this does not fully provide the compatibility stated in the PR description. Use an alias or arrange the hierarchy so MessageId instances also satisfy the deprecated name while preserving the desired warning behavior.
class MessageID(MessageId):

telebot/types.py:4858

  • The deprecated base no longer acts as a compatibility type: every existing non-cached result class was changed to inherit InlineQueryResult directly, so isinstance(InlineQueryResultArticle(...), InlineQueryResultBase) changes from true to false. Keep the old name as an alias or place it above the new class in the inheritance chain so existing base-class checks and type annotations continue to work during deprecation.
class InlineQueryResultBase(InlineQueryResult):

telebot/types.py:4795

  • This new public base claims to represent all 20 inline-query result types and is now used by API method annotations, but the eight InlineQueryResultCached* classes still inherit only InlineQueryResultCachedBase. Consequently valid cached results are not InlineQueryResult instances and are rejected by static type checkers for methods such as answer_web_app_query. Make the cached base derive from this common public base, or define the public annotation as a union covering both hierarchies.
class InlineQueryResult(ABC, Dictionaryable, JsonSerializable):

1. MessageId inherit MessageID to fix compatibility issues mentioned by CoPilot.

2. InlineQueryResult inherit InlineQueryResultBase to fix compatibility issues mentioned by CoPilot.

3. InlineQueryResult inherit InlineQueryResultCachedBase inherit InlineQueryResultBase to remove InlineQueryResultBase - no such class in API, all InlineQueryResultCachedxxx are based on InlineQueryResult

4. description and show_caption_above_media added to InlineQueryResult to short inherited code.

5. InlineQueryResultCachedxxx equipped with to_dict() as far as they are Dictionaryable. I don't know how they work before - specific fields were passed to payload_dic but never used...

6. deprecated properties like "thumb_url" were removed: I was wrong when added them: these classes are not JsonDeserializable, so no one should READ fields...
@Badiboy

Badiboy commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author

Last commit - big base classes revision.

  1. MessageId inherit MessageID to fix compatibility issues mentioned by CoPilot.

  2. InlineQueryResult inherit InlineQueryResultBase to fix compatibility issues mentioned by CoPilot.

  3. InlineQueryResult inherit InlineQueryResultCachedBase inherit InlineQueryResultBase to remove InlineQueryResultBase - no such class in API, all InlineQueryResultCachedxxx are based on InlineQueryResult

  4. description and show_caption_above_media added to InlineQueryResult to short inherited code.

  5. InlineQueryResultCachedxxx equipped with to_dict() as far as they are Dictionaryable. I don't know how they work before - specific fields were passed to payload_dic but never used...

  6. deprecated properties like "thumb_url" were removed: I was wrong when added them: these classes are not JsonDeserializable, so no one should READ fields...

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 6 out of 6 changed files in this pull request and generated 1 comment.

Suppressed comments (3)

telebot/types.py:4833

  • This inheritance preserves nominal compatibility by making every result—including InlineQueryResultArticle—an InlineQueryResultCachedBase, while the deprecated bases no longer retain their former constructor/serialization behavior. Runtime dispatch using the cached base becomes incorrect, and existing custom subclasses that call the old base constructors break. Make InlineQueryResult the common implementation and retain the two legacy bases as compatibility wrappers on their appropriate non-cached/cached branches.
class InlineQueryResult(InlineQueryResultCachedBase, ABC):

telebot/types.py:4936

  • The documented type now contradicts the unchanged constructor: hide_url is still Optional[bool], not a string. Keep this documented as bool even though the parameter is deprecated.
    :type hide_url: :obj:`str`

telebot/types.py:6251

  • title is not a parameter or local variable in InlineQueryResultCachedAudio.__init__, so every construction of this result raises NameError before setting audio_file_id. Remove this keyword from the base call; cached audio results do not define a title.
        super().__init__('audio', id, title = title, caption = caption,

Comment thread telebot/types.py

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 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (4)

telebot/types.py:4895

  • The unified serializer and migrations of all cached result classes are not exercised by the test suite; the only test change covers MessageId. Add representative cached and non-cached serialization tests, including subtype compatibility and optional fields such as description and show_caption_above_media=False, so regressions in the new shared path are detected.
    def to_json(self):
        return json.dumps(self.to_dict())

    def to_dict(self):

telebot/types.py:965

  • MessageId is independent of the deprecated compatibility class, so values now returned by copy_message(s)/forward_messages no longer satisfy existing isinstance(value, MessageID) checks. Make the canonical class inherit the compatibility class; its own __init__ already avoids emitting the deprecation warning for new-name users.
class MessageId(JsonDeserializable, ABC):

telebot/types.py:4842

  • This inheritance makes every result—including non-cached results such as InlineQueryResultArticle—an InlineQueryResultCachedBase. That reverses the previous runtime distinction and can send existing isinstance(..., InlineQueryResultCachedBase) dispatch down the cached path. Define InlineQueryResult from InlineQueryResultBase, then make InlineQueryResultCachedBase inherit the implemented class and use it only for the cached subclasses.
class InlineQueryResult(InlineQueryResultCachedBase, ABC):

telebot/types.py:4968

  • After removing hide_url from subclass serialization, the compatibility branch sets url to '', but to_dict() still uses a truthiness check and therefore omits url entirely. This also contradicts the new guidance to pass an empty URL. Serialize any explicitly supplied URL, including the empty string.
        super().__init__('article', id, title = title, input_message_content = input_message_content,
                         reply_markup = reply_markup, description = description)

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 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (2)

telebot/types.py:4842

  • Making InlineQueryResult inherit InlineQueryResultCachedBase means every non-cached result, such as InlineQueryResultArticle and URL-based InlineQueryResultPhoto, now passes isinstance(result, InlineQueryResultCachedBase). This breaks the cached/non-cached distinction exposed by the legacy base. Make InlineQueryResult derive from the general compatibility base, then derive the cached compatibility base from it and use that base only for the InlineQueryResultCached* classes.
class InlineQueryResult(InlineQueryResultCachedBase, ABC):

telebot/types.py:4832

  • InlineQueryResultBase is retained and documented as deprecated, but it no longer provides the initializer or serialization methods that it provided before this change. Existing user-defined subclasses that still inherit this compatibility type will now fall through to Dictionaryable.to_dict() / JsonSerializable.to_json() and raise NotImplementedError. Keep forwarding implementations on the deprecated base (or make the old name an alias of the functional implementation) so retaining the name actually preserves existing subclasses.
class InlineQueryResultBase(Dictionaryable, JsonSerializable, ABC):
    """
    Deprecated. Use `InlineQueryResult` instead.
    """

@Badiboy

Badiboy commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator Author

Let's stop on this now.

@coder2020official Sorry for so much noise yesterday/today. I had no plans to revise types, but life brought me here 😂

I'll be AFK next days so hope will not disturb you for some time )

@coder2020official

Copy link
Copy Markdown
Collaborator

I can take some time reviewing this

@Badiboy

Badiboy commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

No problem, I understand. Just do not forget )

I currently work on automation of validation of classes (types.py). And hope to get with it the automation of generation updates for bot API changes there.

@Badiboy

Badiboy commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator Author

Just to be clear. The update in this PR is a first step to automation: it aligns classes naming with API. Of course I can bypass these differences, but I propose to align them.

@coder2020official

Copy link
Copy Markdown
Collaborator

You mean you're trying to auto-generate every API update? Sounds great

@coder2020official

Copy link
Copy Markdown
Collaborator

lgtm

@Badiboy
Badiboy merged commit acb0dbb into eternnoir:master Aug 18, 2026
6 checks passed
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