@@ -236,33 +236,40 @@ def add_item(self, item: ViewItem[V]) -> Self:
236236 raise TypeError (f"expected ViewItem not { item .__class__ !r} " )
237237
238238 item .parent = self
239- item ._view = self
240239 self .children .append (item )
241240 return self
242241
243- def remove_item (self , item : ViewItem [V ] | int | str ) -> None :
242+ def remove_item (self , item : ViewItem [V ] | int | str ) -> Self :
244243 """Removes an item from the view. If an :class:`int` or :class:`str` is passed,
245244 the item will be removed by ViewItem ``id`` or ``custom_id`` respectively.
246245
247246 Parameters
248247 ----------
249248 item: Union[:class:`ViewItem`, :class:`int`, :class:`str`]
250249 The item, item ``id``, or item ``custom_id`` to remove from the view.
250+
251+ Returns
252+ -------
253+ :class:`BaseView`
254+ The view instance.
251255 """
252256
253257 if isinstance (item , (str , int )):
254258 item = self .get_item (item )
255259 try :
256- if isinstance ( item .parent , BaseView ) :
260+ if item .parent is self :
257261 self .children .remove (item )
258262 else :
259263 item .parent .remove_item (item )
260264 except ValueError :
261265 pass
266+ item .parent = None
262267 return self
263268
264- def clear_items (self ) -> None :
269+ def clear_items (self ) -> Self :
265270 """Removes all items from this view."""
271+ for child in self .children :
272+ child .parent = None
266273 self .children .clear ()
267274 return self
268275
@@ -580,7 +587,6 @@ def __init__(
580587 ** func .__discord_ui_model_kwargs__
581588 )
582589 item .callback = partial (func , self , item )
583- item ._view = self
584590 item .parent = self
585591 setattr (self , func .__name__ , item )
586592 self .children .append (item )
@@ -887,8 +893,6 @@ def add_item(self, item: ViewItem[V]) -> Self:
887893 )
888894
889895 super ().add_item (item )
890- if hasattr (item , "items" ):
891- item .view = self
892896 return self
893897
894898 def refresh (self , components : list [Component ]):
0 commit comments