-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Make (most) objects comparable #1724
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
Conversation
equality test for |
thanks for asking me to review, but I gonna decline, this is too much for me :D |
|
# Conflicts: # tests/test_inlinekeyboardmarkup.py
Just a thought: should we make Edit: I just went for it (see commit below) |
# Conflicts: # telegram/base.py # tests/test_dice.py # tests/test_poll.py
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.
As far as I can tell looks fine.
One question, though.
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.
Went through the _id_attrs
it set again and actually found some discussion points. Also I was thinking about if/how this behaviour should be documented. I see different possibilities here:
- Don't document. It's a detail for advanced users, who can read code. Also we don't want to make promises
- Make a note on
TelegramObject
along the lines "If the object has an ID, that's the one. If not, it's mostly the required args + meaningful optionals. We can't make promises. Check the code" - Make a note on every object, which attrs are checked.
|
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.
Looks good to me.
Sorry, I forgot the actual issue I have with this: Documentation. I like that you wrote down what gets compared where, but I dont like that being before the attributes of the object. I feel like most users will want to read about attributes rather then what gets compared if they compare this object, which means they have to read over this all the time when they open the docs. What about putting the what-gets-compared paragraph at the end, after the parameters? |
I fear that it's heard to find it there, especially in the docs of classes with many attributes. And it's only 1-3 lines, so it doesn't take up too much space, imo … The alternative would be to have an explicit docstring for |
Some concerns about this PR were voiced offline. I'll try to summarize in hopes of not missing the point:
I'd like to add that this argumentation not only sees harm in this PR but also in the current use of While I don't agree with this argumentation, I find the arguments important and like to have this properly discussed before going for merge. For completeness sake, here is my line of thought:
|
# Conflicts: # tests/test_telegramobject.py
We discussed the PR in the dev chat again and decided to merge. |
* Make most objects comparable * ID attrs for PollAnswer * fix test_game * fix test_userprofilephotos * update for API 4.7 * Warn on meaningless comparisons * Update for API 4.8 * Address review * Get started on docs, update Message._id_attrs * Change PollOption & InputLocation * Some more changes * Even more changes
* Make most objects comparable * ID attrs for PollAnswer * fix test_game * fix test_userprofilephotos * update for API 4.7 * Warn on meaningless comparisons * Update for API 4.8 * Address review * Get started on docs, update Message._id_attrs * Change PollOption & InputLocation * Some more changes * Even more changes
* Make most objects comparable * ID attrs for PollAnswer * fix test_game * fix test_userprofilephotos * update for API 4.7 * Warn on meaningless comparisons * Update for API 4.8 * Address review * Get started on docs, update Message._id_attrs * Change PollOption & InputLocation * Some more changes * Even more changes
* Make most objects comparable * ID attrs for PollAnswer * fix test_game * fix test_userprofilephotos * update for API 4.7 * Warn on meaningless comparisons * Update for API 4.8 * Address review * Get started on docs, update Message._id_attrs * Change PollOption & InputLocation * Some more changes * Even more changes
Closes #1708
Added
_id_attrs
to most of the telegram objects (more or less) by the following paradigm:Also added the corresponding tests.
On the way I encountered some difficulties:
__hash__
to use a tuple representation of the lists, e.g.InlineKeyboardMarkup
ReplyKeyboardMarkup
accepts both strings andKeyboardButtons
while converting stings toKB
only onto_dict
. So I overwrote__equal__
to cope with thisWebhookInfo
. I added oneInputFile.input_media_content
for equality (in case an actual file handler is passed, that is), so I left that andInputMedia…
out_id_attrs
set and it seemed to me that all the other classes have no stand alone tests. So I left them out as well …Needs to be updated, when
are merged