Skip to content

Bot API 7.11: Add allow_paid_broadcast Argument to Bot Methods #4550

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 2 commits into from
Nov 3, 2024

Conversation

Bibo-Joshi
Copy link
Member

Also does some simplification in the spirit of #3369

@Bibo-Joshi Bibo-Joshi added the ⚙️ bot-api affected functionality: bot-api label Nov 2, 2024
@Bibo-Joshi Bibo-Joshi mentioned this pull request Nov 2, 2024
5 tasks
Copy link

codecov bot commented Nov 2, 2024

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
5981 1 5980 281
View the top 1 failed tests by shortest run time
tests.test_callbackquery.TestCallbackQueryWithoutRequest test_copy_message[message]
Stack Traces | 0.003s run time
self = <tests.test_callbackquery.TestCallbackQueryWithoutRequest object at 0x00000240010314F0>
monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x000002400100B850>
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 0x000002407E179940>
bot_method = <function Bot.copy_message at 0x000002407E1D1BC0>
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 2, 2024
6 tasks
@Bibo-Joshi Bibo-Joshi changed the title Add allow_paid_broadcast Argument to Bot Methods Bot API 7.11: Add allow_paid_broadcast Argument to Bot Methods Nov 2, 2024
Copy link
Member

@Poolitzer Poolitzer left a comment

Choose a reason for hiding this comment

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

What an annoying change :D

@Bibo-Joshi
Copy link
Member Author

search & replace did most the work :)

@Bibo-Joshi Bibo-Joshi merged commit b8309ec into api-7.11 Nov 3, 2024
4 of 20 checks passed
@Bibo-Joshi Bibo-Joshi deleted the api-7.11-allow-paid-broadcast branch November 3, 2024 14:18
@github-actions github-actions bot locked and limited conversation to collaborators Nov 11, 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.

2 participants