-
-
Notifications
You must be signed in to change notification settings - Fork 481
refactor: rework how item.view is determined #2981
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?
Conversation
|
Thanks for opening this pull request! This pull request can be checked-out with: git fetch origin pull/2981/head:pr-2981
git checkout pr-2981This pull request can be installed with: pip install git+https://github.com/Pycord-Development/pycord@refs/pull/2981/head |
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.
Pull Request Overview
This PR refactors how ViewItem.view is determined by removing direct view reference propagation in favor of a parent-based traversal approach. Previously, every item held a direct reference to the view that was passed and updated across items, which broke in the cv2 rewrite. Now, items only track their immediate parent and recursively traverse the parent chain to find the view when needed.
Key changes:
- Replaced direct
item._viewassignments with parent-only tracking across all container types - Implemented recursive view resolution through the parent chain in
ViewItem.viewproperty - Deprecated manual
.viewsetter with warning for removal in v2.8
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| discord/ui/view.py | Removed direct _view assignment in add_item, updated remove_item to use identity check and clear parent, fixed clear_items to properly clear parent references |
| discord/ui/section.py | Removed _view assignment in set_accessory and deleted the custom view setter that propagated view references to child items |
| discord/ui/item.py | Implemented recursive parent traversal in view property getter and added deprecation warning to the setter |
| discord/ui/container.py | Removed _view assignment logic in add_item, updated remove_item to use identity check and clear parent |
| discord/ui/action_row.py | Removed _view assignment in add_item, added parent clearing in remove_item |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]> Signed-off-by: plun1331 <[email protected]>
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.
This addresses everything I was gonna pr later and then some so yeah lgtm 🙏
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.
Thoughts on removing i.view = ... entirely?
I'm inclined to say no because then it'd actually be breaking from 2.6.1, but the deprecation itself is fine by me |
Summary
This changes the way that
ViewItem.viewis determined.Before:
Now:
I have deprecated manually setting
.view, though I am considering removing it outright, though that would be breaking. Open for discussion.Information
examples, ...).
Checklist
type: ignorecomments were used, a comment is also left explaining why.