Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Bibo-Joshi merged 18 commits intov13fromid_attrs
Jul 14, 2020
Merged

Make (most) objects comparable#1724

Bibo-Joshi merged 18 commits intov13fromid_attrs
Jul 14, 2020

Conversation

Bibo-Joshi
Copy link
Member

@Bibo-JoshiBibo-Joshi commentedJan 23, 2020
edited
Loading

Closes#1708

Added_id_attrs to most of the telegram objects (more or less) by the following paradigm:

  1. If object has some sort of ID, just use that
  2. If object has only optional args, use all of them
  3. If object has required arg, use that
  4. If object hast required arg and exactly one of the optionals must be given, use all

Also added the corresponding tests.

On the way I encountered some difficulties:

  1. Objects with nested lists as attributes, which are not hashable: I had to overwrite__hash__ to use a tuple representation of the lists, e.g.InlineKeyboardMarkup
  2. ReplyKeyboardMarkup accepts both strings andKeyboardButtons while converting stings toKB only onto_dict. So I overwrote__equal__ to cope with this
  3. There was no test forWebhookInfo. I added one
  4. I couldn't come up with a clever way to testInputFile.input_media_content for equality (in case an actual file handler is passed, that is), so I left that andInputMedia… out
  5. I have no clue of the passport module. All objects that have an ID already had the_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

@Bibo-JoshiBibo-Joshi added enhancement ⚙️ testsaffected functionality: tests labelsJan 23, 2020
@Bibo-JoshiBibo-Joshi added this to the12.5 milestoneJan 23, 2020
@Bibo-Joshi
Copy link
MemberAuthor

equality test forInlineKeyboardMarkup fails on Py2.7. Don't know why, but don't really care 🤷‍♂

@Bibo-JoshiBibo-Joshi mentioned this pull requestJan 24, 2020
2 tasks
@Poolitzer
Copy link
Member

thanks for asking me to review, but I gonna decline, this is too much for me :D

@PoolitzerPoolitzer removed their request for reviewJanuary 25, 2020 04:41
@PoolitzerPoolitzer added the 📋 pending-reviewwork status: pending-review labelJan 25, 2020
@Bibo-Joshi
Copy link
MemberAuthor

test_set_game_score_1 is the one again …

@Bibo-Joshi
Copy link
MemberAuthor

Bibo-Joshi commentedApr 19, 2020
edited
Loading

Just a thought: should we makeTelegramObject.__eq__ raise an error or warning, if it's comparing two objects, one of which has an emtpy_id_attrs tuple, i.e. it's not comparable?

Edit: I just went for it (see commit below)

@Bibo-JoshiBibo-Joshi mentioned this pull requestApr 20, 2020
Copy link
Member

@tsnoamtsnoam left a 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.

Copy link
MemberAuthor

@Bibo-JoshiBibo-Joshi left a 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 onTelegramObject 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.

@Bibo-Joshi
Copy link
MemberAuthor

  • Added documentation, also for the classes, who already had id attrs.
  • Addressed some of the above mentioned stuff
  • In the process, I addedmessage.chat to the id attrs, asmessage_id is not unique across chats. Strictly speaking this is somewhat breaking. Then again, the behaviour wasn't documented yet, so I'd sleep well with that …
  • Coday complains: Access to a protected member _id_attrs of a client class:if other._id_attrs == (): That's okay imo.
  • py3.6 fails onset_game_score

@Bibo-JoshiBibo-Joshi modified the milestones:12.6,13.0Jun 12, 2020
Copy link
Member

@PoolitzerPoolitzer left a 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.

@Poolitzer
Copy link
Member

Poolitzer commentedJun 23, 2020
edited
Loading

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?

@Bibo-Joshi
Copy link
MemberAuthor

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__eq__(), but I don't think that I like that …

@Bibo-Joshi
Copy link
MemberAuthor

Bibo-Joshi commentedJul 13, 2020
edited
Loading

Some concerns about this PR were voiced offline. I'll try to summarize in hopes of not missing the point:

  • Implementing__eq__() to compare only a subset of a classes attributes will be unintuitive for users
  • This is especially true for TG objects that can change, e.g. twoMessage objects will be equal when testing formessage_id only, while maybe having different text
  • Custom comparison by attributes in easy to achive, so there is no reason to implement__eq__()

I'd like to add that this argumentation not only sees harm in this PR but also in the current use of_id_attrs

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:

  • We already have__eq__() implemented for objects with some kind of ID. So we could a) remove that capability, b) leave it as is, or c) extend it to all/most objects
  • The default implementation of__eq__() is useless - I'd rather useis, if I want to compare by object identity. So giving objects a meaningful comparison is crucial imo, which is why I went for c)
  • Currently this PR aims to set_id_attrs to the attrs that uniquely identify an object, i.e. this comparison is the "correct" one in most use cases
  • This PR adds documentation, so== is no black box and if users need a different comparison, they can still implement that

@Bibo-JoshiBibo-Joshi changed the base branch frommaster tov13July 14, 2020 17:24
@Bibo-Joshi
Copy link
MemberAuthor

We discussed the PR in the dev chat again and decided to merge.
I went over the changes once again ad made some minor corrections.
py3.8 fail unrelated, codacy has v13 issues. Merging.

@Bibo-JoshiBibo-Joshi merged commit8855292 intov13Jul 14, 2020
@Bibo-JoshiBibo-Joshi deleted the id_attrs branchJuly 14, 2020 19:34
Bibo-Joshi added a commit that referenced this pull requestJul 14, 2020
* 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
@Bibo-JoshiBibo-Joshi mentioned this pull requestJul 18, 2020
Bibo-Joshi added a commit that referenced this pull requestJul 19, 2020
* 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
Bibo-Joshi added a commit that referenced this pull requestAug 13, 2020
* 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
Bibo-Joshi added a commit that referenced this pull requestAug 16, 2020
* 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
@github-actionsgithub-actionsbot locked asresolvedand limited conversation to collaboratorsAug 17, 2020
@Bibo-JoshiBibo-Joshi added 🔌 enhancementpr description: enhancement and removed enhancement labelsNov 3, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@tsnoamtsnoamtsnoam left review comments

@PoolitzerPoolitzerPoolitzer approved these changes

@EldinnieEldinnieAwaiting requested review from Eldinnie

Assignees
No one assigned
Labels
🔌 enhancementpr description: enhancement📋 pending-reviewwork status: pending-review⚙️ testsaffected functionality: tests
Projects
None yet
Milestone
13.0
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add _id_attrs
3 participants
@Bibo-Joshi@Poolitzer@tsnoam

[8]ページ先頭

©2009-2025 Movatter.jp