Skip to content

Bot API 7.11 #4546

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 11 commits into from
Nov 4, 2024
Merged

Bot API 7.11 #4546

merged 11 commits into from
Nov 4, 2024

Conversation

Bibo-Joshi
Copy link
Member

@Bibo-Joshi Bibo-Joshi commented Nov 1, 2024

closes #4543. Please have a look at that issue for how the work is distributed.

  • Added .. versionadded:: NEXT.VERSION, .. versionchanged:: NEXT.VERSION, .. deprecated:: NEXT.VERSION or .. versionremoved:: NEXT.VERSION to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Documented code changes according to the CSI standard
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new classes & modules to the docs and all suitable __all__ s
  • Checked the Stability Policy in case of deprecations or changes to documented behavior

If the PR contains API changes (otherwise, you can ignore this passage)

  • Checked the Bot API specific sections of the Stability Policy

  • Created a PR to remove functionality deprecated in the previous Bot API release (see here)

  • New classes:

    • Added self._id_attrs and corresponding documentation
    • __init__ accepts api_kwargs as kw-only
  • Added new shortcuts:

    • In telegram.Chat & telegram.User for all methods that accept chat/user_id
    • In telegram.Message for all methods that accept chat_id and message_id
    • For new telegram.Message shortcuts: Added quote argument if methods accepts reply_to_message_id
    • In telegram.CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id
  • If relevant:

    • Added new constants at telegram.constants and shortcuts to them as class variables
    • Link new and existing constants in docstrings instead of hard-coded numbers and strings
    • Add new message types to telegram.Message.effective_attachment
    • Added new handlers for new update types
      • Add the handlers to the warning loop in the telegram.ext.ConversationHandler
    • Added new filters for new message (sub)types
    • Added or updated documentation for the changed class(es) and/or method(s)
    • Added the new method(s) to _extbot.py
    • Added or updated bot_methods.rst
    • Updated the Bot API version number in all places: README.rst (including the badge) and telegram.constants.BOT_API_VERSION_INFO
    • Added logic for arbitrary callback data in telegram.ext.ExtBot for new methods that either accept a reply_markup in some form or have a return type that is/contains telegram.Message

@Bibo-Joshi Bibo-Joshi added the ⚙️ bot-api affected functionality: bot-api label Nov 1, 2024
Copy link

codecov bot commented Nov 1, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
6004 1 6003 271
View the top 1 failed tests by shortest run time
tests.test_callbackquery.TestCallbackQueryWithoutRequest test_copy_message[message]
Stack Traces | 0.002s run time
self = <tests.test_callbackquery.TestCallbackQueryWithoutRequest object at 0x0000022AA3095AE0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x0000022AA306B3F0>
callback_query = CallbackQuery(chat_instance='chat_instance', data='data', from_user=User(first_name='test_user', id=1, is_bot=False), ...ser=User(first_name='bot', id=5, is_bot=False), group_chat_created=False, message_id=3, supergroup_chat_created=False))

    async def test_copy_message(self, monkeypatch, callback_query):
        if isinstance(callback_query.message, InaccessibleMessage):
            with pytest.raises(TypeError, match="inaccessible message"):
                await callback_query.copy_message(1)
            return
        if callback_query.inline_message_id:
            pytest.skip("Can't copy inline messages")
    
        async def make_assertion(*args, **kwargs):
            id_ = kwargs["from_chat_id"] == callback_query.message.chat_id
            chat_id = kwargs["chat_id"] == 1
            message = kwargs["message_id"] == callback_query.message.message_id
            return id_ and message and chat_id
    
>       assert check_shortcut_signature(
            CallbackQuery.copy_message,
            Bot.copy_message,
            ["message_id", "from_chat_id"],
            [],
        )

tests\test_callbackquery.py:527: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

shortcut = <function CallbackQuery.copy_message at 0x0000022AA018DA80>
bot_method = <function Bot.copy_message at 0x0000022AA01E1D00>
shortcut_kwargs = ['message_id', 'from_chat_id'], additional_kwargs = []
annotation_overrides = {}

    def check_shortcut_signature(
        shortcut: Callable,
        bot_method: Callable,
        shortcut_kwargs: list[str],
        additional_kwargs: list[str],
        annotation_overrides: Optional[dict[str, tuple[Any, Any]]] = None,
    ) -> bool:
        """
        Checks that the signature of a shortcut matches the signature of the underlying bot method.
    
        Args:
            shortcut: The shortcut, e.g. :meth:`telegram.Message.reply_text`
            bot_method: The bot method, e.g. :meth:`telegram.Bot.send_message`
            shortcut_kwargs: The kwargs passed by the shortcut directly, e.g. ``chat_id``
            additional_kwargs: Additional kwargs of the shortcut that the bot method doesn't have, e.g.
                ``quote``.
            annotation_overrides: A dictionary of exceptions for the annotation comparison. The key is
                the name of the argument, the value is a tuple of the expected annotation and
                the default value. E.g. ``{'parse_mode': (str, 'None')}``.
    
        Returns:
            :obj:`bool`: Whether or not the signature matches.
        """
        annotation_overrides = annotation_overrides or {}
    
        def resolve_class(class_name: str) -> Optional[type]:
            """Attempts to resolve a PTB class (telegram module only) from a ForwardRef.
    
            E.g. resolves <class 'telegram._files.sticker.StickerSet'> from "StickerSet".
    
            Returns a class on success, :obj:`None` if nothing could be resolved.
            """
            for module in telegram, telegram.request:
                cls = getattr(module, class_name, None)
                if cls is not None:
                    return cls
            return None  # for ruff
    
        shortcut_sig = inspect.signature(shortcut)
        effective_shortcut_args = set(shortcut_sig.parameters.keys()).difference(additional_kwargs)
        effective_shortcut_args.discard("self")
    
        bot_sig = inspect.signature(bot_method)
        expected_args = set(bot_sig.parameters.keys()).difference(shortcut_kwargs)
        expected_args.discard("self")
    
        len_expected = len(expected_args)
        len_effective = len(effective_shortcut_args)
        if len_expected > len_effective:
>           raise Exception(
                f"Shortcut signature is missing {len_expected - len_effective} arguments "
                f"of the underlying Bot method: {expected_args - effective_shortcut_args}"
            )
E           Exception: Shortcut signature is missing 1 arguments of the underlying Bot method: {'allow_paid_broadcast'}

tests\auxil\bot_method_checks.py:107: Exception

To view individual test run time comparison to the main branch, go to the Test Analytics Dashboard

@Bibo-Joshi Bibo-Joshi mentioned this pull request Nov 1, 2024
5 tasks
@Bibo-Joshi Bibo-Joshi mentioned this pull request Nov 2, 2024
6 tasks
Copy link
Member Author

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

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

Scrolled through the changes one more time and didn't find anything suspicious. Checks pass - merging.

@Bibo-Joshi Bibo-Joshi merged commit 62f8975 into master Nov 4, 2024
24 checks passed
@Bibo-Joshi Bibo-Joshi deleted the api-7.11 branch November 4, 2024 19:11
@github-actions github-actions bot locked and limited conversation to collaborators Nov 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
⚙️ bot-api affected functionality: bot-api
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] API 7.11
1 participant