Add a swap method for dynamic item's dispatching

This commit is contained in:
DA344
2025-08-21 00:52:31 +02:00
committed by GitHub
parent b2aab86ba1
commit 0309aac335
5 changed files with 26 additions and 3 deletions

View File

@ -35,6 +35,7 @@ if TYPE_CHECKING:
from typing_extensions import Self
from .view import LayoutView
from .dynamic import DynamicItem
from ..components import SectionComponent
V = TypeVar('V', bound='LayoutView', covariant=True)
@ -117,6 +118,10 @@ class Section(Item[V]):
def _is_v2(self) -> bool:
return True
def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
if self.accessory.is_dispatchable() and getattr(self.accessory, 'custom_id', None) == custom_id:
self.accessory = new # type: ignore
def walk_children(self) -> Generator[Item[V], None, None]:
"""An iterator that recursively walks through all the children of this section
and its children, if applicable. This includes the `accessory`.