2424
2525from __future__ import annotations
2626
27+ import copy
2728from typing import (
2829 TYPE_CHECKING ,
2930 Any ,
3031 Callable ,
3132 ClassVar ,
32- Coroutine ,
3333 Dict ,
3434 Generator ,
3535 List ,
4242 overload ,
4343)
4444
45- from .item import Item , ContainedItemCallbackType as ItemCallbackType
45+ from .item import Item , ContainedItemCallbackType as ItemCallbackType , _ItemCallback
4646from .button import Button , button as _button
4747from .select import select as _select , Select , UserSelect , RoleSelect , ChannelSelect , MentionableSelect
4848from ..components import ActionRow as ActionRowComponent
6565 )
6666 from ..emoji import Emoji
6767 from ..components import SelectOption
68- from ..interactions import Interaction
6968 from .container import Container
7069 from .dynamic import DynamicItem
7170
7776__all__ = ('ActionRow' ,)
7877
7978
80- class _ActionRowCallback :
81- __slots__ = ('row' , 'callback' , 'item' )
82-
83- def __init__ (self , callback : ItemCallbackType [S , Any ], row : ActionRow , item : Item [Any ]) -> None :
84- self .callback : ItemCallbackType [Any , Any ] = callback
85- self .row : ActionRow = row
86- self .item : Item [Any ] = item
87-
88- def __call__ (self , interaction : Interaction ) -> Coroutine [Any , Any , Any ]:
89- return self .callback (self .row , interaction , self .item )
90-
91-
9279class ActionRow (Item [V ]):
9380 r"""Represents a UI action row.
9481
@@ -143,8 +130,9 @@ def __init__(
143130 ) -> None :
144131 super ().__init__ ()
145132 self ._children : List [Item [V ]] = self ._init_children ()
146- self ._children .extend (children )
147133 self ._weight : int = sum (i .width for i in self ._children )
134+ for child in children :
135+ self .add_item (child )
148136
149137 if self ._weight > 5 :
150138 raise ValueError ('maximum number of children exceeded' )
@@ -173,8 +161,8 @@ def _init_children(self) -> List[Item[Any]]:
173161
174162 for func in self .__action_row_children_items__ :
175163 item : Item = func .__discord_ui_model_type__ (** func .__discord_ui_model_kwargs__ )
176- item .callback = _ActionRowCallback (func , self , item ) # type: ignore
177- item ._parent = getattr ( func , '__discord_ui_parent__' , self )
164+ item .callback = _ItemCallback (func , self , item ) # type: ignore
165+ item ._parent = self
178166 setattr (self , func .__name__ , item )
179167 children .append (item )
180168 return children
@@ -184,6 +172,23 @@ def _update_view(self, view) -> None:
184172 for child in self ._children :
185173 child ._view = view
186174
175+ def copy (self ) -> ActionRow [V ]:
176+ new = copy .copy (self )
177+ children = []
178+ for child in new ._children :
179+ newch = child .copy ()
180+ newch ._parent = new
181+ if isinstance (newch .callback , _ItemCallback ):
182+ newch .callback .parent = new
183+ children .append (newch )
184+ new ._children = children
185+ new ._parent = self ._parent
186+ new ._update_view (self .view )
187+ return new
188+
189+ def __deepcopy__ (self , memo ) -> ActionRow [V ]:
190+ return self .copy ()
191+
187192 def _has_children (self ):
188193 return True
189194
0 commit comments