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
Make TelegramObject
immutable
#3249
Conversation
# Conflicts: # docs/substitutions/global.rst
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.
most of my comments are just about docs, type hinting and the None/empty tuple thing:
Dedum … using |
I addressed this by making So far, I see only one side-effect of this: if there is any class attribute where it makes a difference if we pass an empty array or nothing at all, this will be a problem. I have not found such an instance. If there is one in the future, one could override If there are other side-effects or concerns about this change that I did not see, please do tell. Personally, I like the consistency of having all sequence-type attributes always being tuples instead of |
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.
I think that approach is good. It would be weird if Telegram decides to consider ()
as something meaningful over nothing.
Besides the deepsource issue to be solved and deleting the temporary immutabilize.py
file, this PR gets a LGTM from me!
# Conflicts: # telegram/ext/_extbot.py
# Conflicts: # tests/conftest.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.
LGTM
I love the freeze/unfreeze change here, good stuff
Currently based on #3233 so that I don't have to add the calls to
super().__init__
everywhere again …A few notes:
Must be adapted onceTelegramObject.api_kwargs
#3233 is merged to make sure thatapi_kwargs
are immutable as wellIn a few places (in(largue alliviated by make (Ext)Bot._insert_defaults copy instead of editing in-place #3311)telegram
), I call the protecded_(un)freeze
methods of objects to altern their values. At least in some of those cases, we could discuss if it would be desirable to instead create a copy of the object.to_dict
sill converts tuples into lists. IMO that's okay, as the dict is mutable anywayTODO:
TelegramObject.__hash__
(if that's still needed, anyway) also includeself.__class_
in the hash to comply with the behavior ofTelegramObject.__hash__
Checklist for PRs
.. versionadded:: version
,.. versionchanged:: version
or.. deprecated:: version
to the docstrings for user facing changes (for methods/class descriptions, arguments and attributes)Added myself alphabetically toAUTHORS.rst
(optional)Added new classes & modules to the docs and all suitable__all__
s