Implement hash for types
- pytelegrambotapi=4.23.0
- Debian 12
- Python 3.11.2
2 user objects with same data will return different hashcode, and will be not equal.
I was collecting poll answers in a dictionary with User key to get the latest answers on each user. However, same user appears multiple time in key set. This is probably due to unimplemented hash method.
>>> a = telebot.types.User(id=1, first_name = 'Dzmitry', is_bot = False)
>>> b = telebot.types.User(id=1, first_name = 'Dzmitry', is_bot = False)
>>> a == b
False
>>> hash(a)
8728866946505
>>> hash(b)
8728866946497
@badiboy maybe we should consider implementing __eq__ in some classes..
@coder2020official I don't think setting classes equality by values is a good idea. I cannot imagine what it may brake.
If you need unique value by user - ID should be used. For the above case just using User.id as a key will solve all needs. And comparing a.id == b.id is not harder but is much more clear.
Why collect poll answers? Telegram does that itself. You don't need to intercept that with your bot.