What kind of feature are you missing? Where do you notice a shortcoming of PTB?
One thing I noticed is that while digging around for potential improvements is that we currently define the _id_attrs in the __init__ of every class, but the information it represents is static and doesn't change with every instance* (see exceptions below)
I propose representing that information as a class variable with strings, which will serve as forward references.
This mainly has 2 advantages:
- When switching to dataclasses (
insert future issue number), we will not need a __post_init__ method to define what attributes to use for equality comparison.
- Memory savings. This would be tiny of course (saving one 8 byte slot pointer every instance + the pointers to the data in the tuple, so at least 48B)
Describe the solution you'd like
This change would move the evaluation of _id_attrs from init time to equality checking time. Inside __eq__, we can iterate through the _id_attrs, and call getattr to fully resolve it. Of course this incurs a performance overhead, but I don't believe most users are ever comparing TelegramObjects that often..
Exceptions
PassportData._id_attrs is doing some dynamic assignments. I'm not sure why it was done that way, that is probably not needed and can be just static.
InlineKeyboardButton._set_id_attrs can be deleted since __eq__ will dynamically fetch the current callback data, so there's nothing to update in the tuple itself.
Describe alternatives you've considered
No response
Additional context
There is the concern of typos in the strings typed out, but since we have equality tests for every class, they should be caught.
What kind of feature are you missing? Where do you notice a shortcoming of PTB?
One thing I noticed is that while digging around for potential improvements is that we currently define the
_id_attrsin the__init__of every class, but the information it represents is static and doesn't change with every instance* (see exceptions below)I propose representing that information as a class variable with strings, which will serve as forward references.
This mainly has 2 advantages:
insert future issue number), we will not need a__post_init__method to define what attributes to use for equality comparison.Describe the solution you'd like
This change would move the evaluation of
_id_attrsfrom init time to equality checking time. Inside__eq__, we can iterate through the_id_attrs, and callgetattrto fully resolve it. Of course this incurs a performance overhead, but I don't believe most users are ever comparing TelegramObjects that often..Exceptions
PassportData._id_attrsis doing some dynamic assignments. I'm not sure why it was done that way, that is probably not needed and can be just static.InlineKeyboardButton._set_id_attrscan be deleted since__eq__will dynamically fetch the current callback data, so there's nothing to update in the tuple itself.Describe alternatives you've considered
No response
Additional context
There is the concern of typos in the strings typed out, but since we have equality tests for every class, they should be caught.