Fix container items having out of date internal state

This commit is contained in:
DA344
2025-11-08 00:53:04 +01:00
committed by GitHub
parent 8f2cb60700
commit e2cf721e9c
6 changed files with 68 additions and 54 deletions

View File

@@ -39,10 +39,11 @@ from typing import (
Sequence,
)
from contextvars import ContextVar
import copy
import inspect
import os
from .item import Item, ContainedItemCallbackType as ItemCallbackType
from .item import Item, ContainedItemCallbackType as ItemCallbackType, _ItemCallback
from ..enums import ChannelType, ComponentType, SelectDefaultValueType
from ..partial_emoji import PartialEmoji
from ..emoji import Emoji
@@ -70,7 +71,7 @@ __all__ = (
)
if TYPE_CHECKING:
from typing_extensions import TypeAlias, TypeGuard
from typing_extensions import TypeAlias, TypeGuard, Self
from .view import BaseView
from .action_row import ActionRow
@@ -269,6 +270,14 @@ class BaseSelect(Item[V]):
self.row = row
self._values: List[PossibleValue] = []
def copy(self) -> Self:
new = copy.copy(self)
if isinstance(new.callback, _ItemCallback):
new.callback.item = new
new._parent = self._parent
new._update_view(self.view)
return new
@property
def id(self) -> Optional[int]:
"""Optional[:class:`int`]: The ID of this select."""