-
-
Notifications
You must be signed in to change notification settings - Fork 479
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
Open
plun1331
wants to merge
9
commits into
master
Choose a base branch
from
fix-view-attr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9663af1
feat: rework how item.view is determined
plun1331 8455d01
docs: changelog
plun1331 c3f0010
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a7b56b5
Update discord/ui/view.py
plun1331 24bb592
remove useless stuff
plun1331 10e19a8
Merge remote-tracking branch 'origin/fix-view-attr' into fix-view-attr
plun1331 d8be20f
fuckin circles man
plun1331 9f9c021
style(pre-commit): auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c4f5514
Merge branch 'master' into fix-view-attr
NeloBlivion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -235,11 +235,10 @@ def add_item(self, item: ViewItem[V]) -> Self: | |
| raise TypeError(f"expected ViewItem not {item.__class__!r}") | ||
|
|
||
| item.parent = self | ||
| item._view = self | ||
| self.children.append(item) | ||
| return self | ||
|
|
||
| def remove_item(self, item: ViewItem[V] | int | str) -> None: | ||
| def remove_item(self, item: ViewItem[V] | int | str) -> Self: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing an updated |
||
| """Removes an item from the view. If an :class:`int` or :class:`str` is passed, | ||
| the item will be removed by ViewItem ``id`` or ``custom_id`` respectively. | ||
|
|
||
|
|
@@ -252,16 +251,19 @@ def remove_item(self, item: ViewItem[V] | int | str) -> None: | |
| if isinstance(item, (str, int)): | ||
| item = self.get_item(item) | ||
| try: | ||
| if isinstance(item.parent, BaseView): | ||
| if item.parent is self: | ||
| self.children.remove(item) | ||
| else: | ||
| item.parent.remove_item(item) | ||
| except ValueError: | ||
| pass | ||
| item.parent = None | ||
| return self | ||
|
|
||
| def clear_items(self) -> None: | ||
| def clear_items(self) -> Self: | ||
| """Removes all items from this view.""" | ||
| for child in self.children: | ||
| child.parent = None | ||
| self.children.clear() | ||
| return self | ||
|
|
||
|
|
@@ -575,7 +577,6 @@ def __init__( | |
| **func.__discord_ui_model_kwargs__ | ||
| ) | ||
| item.callback = partial(func, self, item) | ||
| item._view = self | ||
| item.parent = self | ||
| setattr(self, func.__name__, item) | ||
| self.children.append(item) | ||
|
|
@@ -882,8 +883,6 @@ def add_item(self, item: ViewItem[V]) -> Self: | |
| ) | ||
|
|
||
| super().add_item(item) | ||
| if hasattr(item, "items"): | ||
| item.view = self | ||
| return self | ||
|
|
||
| def refresh(self, components: list[Component]): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Isn't this non semver-compliant ?
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.
agree with paillat, should be removed in 3.0