-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[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
[REFACTOR] Shortcut bots handling #2712
Conversation
There was a problem hiding this 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 :)
There was a problem hiding this 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 raisesRuntimeError
- calling
get_bot()
after having set a bot instance withset_bot
returns the same object - calling
set_bot(None)
after that leads toget_bot()
raisingRuntimeError
again
There was a problem hiding this 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 :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small annotations
telegram/_passport/data.py
Outdated
|
||
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
telegram/_telegramobject.py
Outdated
if self._bot is None: | ||
raise RuntimeError( | ||
'This object has no bot associated with it. \ | ||
Shortcuts cannot be used' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shortcuts cannot be used' | |
Shortcuts cannot be used.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
tests/test_audio.py
Outdated
@@ -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') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
tests/test_shippingquery.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap.
Thanks for the contribution. |
Addresses #2505.
Checklist for PRs
.. versionadded:: version
,.. versionchanged:: version
or.. deprecated:: version
to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)AUTHORS.rst
(optional)Chat
&User
for all methods that acceptchat/user_id
Message
for all methods that acceptchat_id
andmessage_id
Message
shortcuts: Addedquote
argument if methods acceptsreply_to_message_id
CallbackQuery
for all methods that accept eitherchat_id
andmessage_id
orinline_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