-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Add __slots__ #2345
Add __slots__ #2345
Conversation
Looks like in python 3.6 |
Also tried to fix that py3.6 test fail Fixed and added some slots Update class attribute properly in updater.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.
Hey, thanks for the big PR! I left a bunch of comments, though I didn't check the slots for ever class and skimmed the test :D
Regarding tests: You currently test for extra slots in each class's test. I would like to see another test that iterates over all modules and makes every class actually has slots. Could go to a standalone test_slots.py
. If testing for additional slots can work on class.__slots__
instead of class instances, one could also think about moving the tests for extra slots to that test file. Would save duplication and we wouldn't have to remember putting the test_extra_slots
in each test file …
Tests that I would also like to see and which could go into test_slots.py
:
- Test that
class.custom_attribute
actually gives a warning - Test that overwriting existing attributes still works and doesn't give a warning
iirc,
I did that for the base classes, but it's probably best I do it for all, just to be sure... (and same for the other point) |
Also adding some missing __setattr__'s
…er w/o warning Code for update/message filter was 2 commits before this one
Ok so the past few commits have allowed subclassing of classes like Handler, etc without raising TGDeprecation warning for setting a new instance attribute (useful for custom The slots tests now test:
and a test_slots.py, which tests if all classes have slots, and that each have a Also |
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.
Hey, thanks for the updates :) Had a look and them and left some comments.
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.
Hey. Thanks for the new updates. I had a look (only at the new changes for now) and left some comments. I'll have to review everything again and would also this PR to be reviewed by someone else before merging, though - tbh it became quite more involved than I had imagined 😬
I'm now gonna run all of the examples and some of my bots based on this branch to further verify that everything is working. Might also compare the memory usage for fun. |
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.
Changes look good to me. They shouldn't break anything anyway, and we can add them later easily.
Resolved issues in the following files via DeepSource Autofix: 1. telegram/ext/filters.py 2. telegram/utils/deprecate.py
This PR adds
__slots__
to all classes (finally!). As discussed in #1109,__dict__
is currently added to slots for backward compatibility.Some notes about the changes:
__weakref__
was added inDispatcher
's__slots__
as we're creating weakrefs with it.to_dict()
inbase.py
so it works with slots_request
an instance attribute inupdater.py
.__dict__
.TelegramDeprecationWarning
is raised when users try to assign new attributes on classes which don't support it.Closes #1109