Browse Source

properly type _swap_item

pull/10271/head
DA-344 2 weeks ago
parent
commit
16f61b1229
  1. 3
      discord/ui/action_row.py
  2. 3
      discord/ui/container.py
  3. 3
      discord/ui/section.py

3
discord/ui/action_row.py

@ -67,6 +67,7 @@ if TYPE_CHECKING:
from ..components import SelectOption from ..components import SelectOption
from ..interactions import Interaction from ..interactions import Interaction
from .container import Container from .container import Container
from .dynamic import DynamicItem
SelectCallbackDecorator = Callable[[ItemCallbackType['S', BaseSelectT]], BaseSelectT] SelectCallbackDecorator = Callable[[ItemCallbackType['S', BaseSelectT]], BaseSelectT]
@ -194,7 +195,7 @@ class ActionRow(Item[V]):
# it should error anyways. # it should error anyways.
return True return True
def _swap_item(self, base, new, custom_id) -> None: def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
child_index = self._children.index(base) child_index = self._children.index(base)
self._children[child_index] = new # type: ignore self._children[child_index] = new # type: ignore

3
discord/ui/container.py

@ -50,6 +50,7 @@ if TYPE_CHECKING:
from ..components import Container as ContainerComponent from ..components import Container as ContainerComponent
from ..interactions import Interaction from ..interactions import Interaction
from .dynamic import DynamicItem
S = TypeVar('S', bound='Container', covariant=True) S = TypeVar('S', bound='Container', covariant=True)
V = TypeVar('V', bound='LayoutView', covariant=True) V = TypeVar('V', bound='LayoutView', covariant=True)
@ -198,7 +199,7 @@ class Container(Item[V]):
def _has_children(self): def _has_children(self):
return True return True
def _swap_item(self, base, new, custom_id) -> None: def _swap_item(self, base: Item, new: DynamicItem, custom_id: str) -> None:
child_index = self._children.index(base) child_index = self._children.index(base)
self._children[child_index] = new # type: ignore self._children[child_index] = new # type: ignore

3
discord/ui/section.py

@ -35,6 +35,7 @@ if TYPE_CHECKING:
from typing_extensions import Self from typing_extensions import Self
from .view import LayoutView from .view import LayoutView
from .dynamic import DynamicItem
from ..components import SectionComponent from ..components import SectionComponent
V = TypeVar('V', bound='LayoutView', covariant=True) V = TypeVar('V', bound='LayoutView', covariant=True)
@ -111,7 +112,7 @@ class Section(Item[V]):
def _is_v2(self) -> bool: def _is_v2(self) -> bool:
return True return True
def _swap_item(self, base, new, custom_id) -> None: 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: if self.accessory.is_dispatchable() and getattr(self.accessory, 'custom_id', None) == custom_id:
self.accessory = new # type: ignore self.accessory = new # type: ignore

Loading…
Cancel
Save