Skip to content

[REFACTOR] Shortcut bots handling #2712

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

Conversation

zpavloudis
Copy link
Contributor

Addresses #2505.

Checklist for PRs

  • Added .. versionadded:: version, .. versionchanged:: version or .. deprecated:: version to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)
  • Created new or adapted existing unit tests
  • Added myself alphabetically to AUTHORS.rst (optional)
  • Added new shortcuts:
    • In Chat & User for all methods that accept chat/user_id
    • In Message for all methods that accept chat_id and message_id
    • For new Message shortcuts: Added quote argument if methods accepts reply_to_message_id
    • In CallbackQuery for all methods that accept either chat_id and message_id or inline_message_id

I'd like to draw your attention to this line as test_slot_behaviour fails with " AssertionError: got extra slot '_bot' without it

@Bibo-Joshi Bibo-Joshi self-requested a review October 8, 2021 16:49
Copy link
Member

@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.

Thanks for the PR! I've added a few comments below :)

Copy link
Member

@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.

The rest of the updates look good :) One thing that I forgot about so far: We should add new unit tests. please add a test to test_telegramobject.py that make sure that:

  • calling get_bot() without having set a bot raises RuntimeError
  • calling get_bot() after having set a bot instance with set_bot returns the same object
  • calling set_bot(None) after that leads to get_bot() raising RuntimeError again

Copy link
Member

@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.

Thanks for the updates! I left just some minor comments :) Besides that, can you merge v14 into your branch to resolve the merge conflicts? #2687 just got merged, which renamed a lot of file (but changed almost nothing in the files). If you're e.g. using pycharm, merging shouldn't bee too hard. If you're having troubles with this, please tell us :)

@Bibo-Joshi Bibo-Joshi added this to the v14 milestone Oct 11, 2021
@Bibo-Joshi Bibo-Joshi requested a review from Poolitzer October 11, 2021 06:57
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.

Small annotations


def __init__(self, document_no: str, expiry_date: str, bot: 'Bot' = None, **_kwargs: Any):
self.document_no = document_no
self.expiry_date = expiry_date

self.bot = bot
self._bot = bot
Copy link
Member

Choose a reason for hiding this comment

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

Maybe Im stupid, why is this different from the other classes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't have been.
Fixed.

if self._bot is None:
raise RuntimeError(
'This object has no bot associated with it. \
Shortcuts cannot be used'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Shortcuts cannot be used'
Shortcuts cannot be used.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -282,10 +282,10 @@ def make_assertion(*_, **kwargs):
return kwargs['file_id'] == audio.file_id

assert check_shortcut_signature(Audio.get_file, Bot.get_file, ['file_id'], [])
assert check_shortcut_call(audio.get_file, audio.bot, 'get_file')
assert check_defaults_handling(audio.get_file, audio.bot)
assert check_shortcut_call(audio.get_file, audio._bot, 'get_file')
Copy link
Member

Choose a reason for hiding this comment

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

shouldnt we use get_bot here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -58,7 +58,7 @@ def test_de_json(self, bot):
assert shipping_query.invoice_payload == self.invoice_payload
assert shipping_query.from_user == self.from_user
assert shipping_query.shipping_address == self.shipping_address
assert shipping_query.bot is bot
assert shipping_query._bot is bot
Copy link
Member

Choose a reason for hiding this comment

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

also, shouldn't this be get_bot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeap.

@Bibo-Joshi Bibo-Joshi added the 📋 pending-review work status: pending-review label Oct 21, 2021
@Poolitzer
Copy link
Member

Thanks for the contribution.

@Poolitzer Poolitzer merged commit 9688d08 into python-telegram-bot:v14 Oct 21, 2021
@zpavloudis zpavloudis deleted the refactor-shortcut-bots-handling branch October 21, 2021 11:35
@github-actions github-actions bot locked and limited conversation to collaborators Oct 22, 2021
@harshil21 harshil21 added the hacktoberfest-accepted other: hacktoberfest-accepted label Oct 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
hacktoberfest-accepted other: hacktoberfest-accepted 📋 pending-review work status: pending-review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy