-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix contained items states #10336
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
base: master
Are you sure you want to change the base?
Fix contained items states #10336
Conversation
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.
Thanks a lot for the patch!
I have been writing test cases on my end to help covering the weird situations, and I'm still failing on your branch checking for ActionRow.parent which should be Container but is None (same example as the issue).
I also noticed that button.parent and self inside the button callback are of the same type (ActionRow), but not the same instance. It's probably due to all the deepcopy going on, I don't know how problematic that actually is.
My bad, my venv was not properly configured and did not use the right code 😓 The only case failing is self.parent.parent being None instead of Layout
Download this file, drop it in the tests folder, and run it with pytest -k test_ui_nested. I think it's worth pushing the test along the PR to avoid regression.
discord/ui/action_row.py
Outdated
| for child in children: | ||
| self.add_item(child) | ||
| self._weight: int = sum(i.width for i in self._children) |
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.
add_item fails because it needs self._weight to exist
| for child in children: | |
| self.add_item(child) | |
| self._weight: int = sum(i.width for i in self._children) | |
| self._weight: int = sum(i.width for i in self._children) | |
| for child in children: | |
| self.add_item(child) |
|
A view will never be a parent, that is why |
|
Oooh, that makes sense alright! Then all of my tests pass |
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'm not sure how I feel about this fix honestly. It's not incorrect but it does feel a bit messy since there are now multiple places where the callback binding needs to be handled. I'm not a fan of that right now though I guess a better approach can be figured out later.
As proof of how finicky this stuff is to deal with now, you forgot to do this to Select components.
Summary
Contained items (in Containers, ActionRows, etc.) had some attributes outdated or uncorrectly set as another value. This PR attempts to fix it.
Checklist