Browse Source

chore: remove unused functions and attributes

pull/10166/head
DA-344 1 month ago
parent
commit
c4225ecd2f
  1. 15
      discord/ui/action_row.py
  2. 48
      discord/ui/container.py

15
discord/ui/action_row.py

@ -195,18 +195,6 @@ class ActionRow(Item[V]):
children.append(item)
return children
def _update_store_data(self, dispatch_info: Dict, dynamic_items: Dict) -> bool:
is_fully_dynamic = True
for item in self._children:
if isinstance(item, DynamicItem):
pattern = item.__discord_ui_compiled_template__
dynamic_items[pattern] = item.__class__
elif item.is_dispatchable():
dispatch_info[(item.type.value, item.custom_id)] = item
is_fully_dynamic = False
return is_fully_dynamic
def _update_children_view(self, view: LayoutView) -> None:
for child in self._children:
child._view = view # pyright: ignore[reportAttributeAccessIssue]
@ -277,9 +265,6 @@ class ActionRow(Item[V]):
if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
self._view._total_children += 1
if item.is_dispatchable() and self._parent and getattr(self._parent, '__discord_ui_container__', False):
self._parent._add_dispatchable(item) # type: ignore
return self
def remove_item(self, item: Item[Any]) -> Self:

48
discord/ui/container.py

@ -149,7 +149,6 @@ class Container(Item[V]):
id: Optional[int] = None,
) -> None:
super().__init__()
self.__dispatchable: List[Item[V]] = []
self._children: List[Item[V]] = self._init_children()
if children is not MISSING:
@ -165,15 +164,6 @@ class Container(Item[V]):
def __repr__(self) -> str:
return f'<{super().__repr__()[:-1]} children={len(self._children)}>'
def _add_dispatchable(self, item: Item[Any]) -> None:
self.__dispatchable.append(item)
def _remove_dispatchable(self, item: Item[Any]) -> None:
try:
self.__dispatchable.remove(item)
except ValueError:
pass
def _init_children(self) -> List[Item[Any]]:
children = []
parents = {}
@ -188,7 +178,6 @@ class Container(Item[V]):
if getattr(item, '__discord_ui_section__', False) and item.accessory.is_dispatchable(): # type: ignore
if item.accessory._provided_custom_id is False: # type: ignore
item.accessory.custom_id = os.urandom(16).hex() # type: ignore
self.__dispatchable.append(item.accessory) # type: ignore
setattr(self, name, item)
children.append(item)
@ -209,7 +198,6 @@ class Container(Item[V]):
parents.get(parent, parent)._children.append(item)
# we donnot append it to the children list because technically these buttons and
# selects are not from the container but the action row itself.
self.__dispatchable.append(item)
return children
@ -298,21 +286,6 @@ class Container(Item[V]):
base['id'] = self.id
return base
def _update_store_data(
self,
dispatch_info: Dict[Tuple[int, str], Item[Any]],
dynamic_items: Dict[Any, Type[DynamicItem]],
) -> bool:
is_fully_dynamic = True
for item in self.__dispatchable:
if isinstance(item, DynamicItem):
pattern = item.__discord_ui_compiled_template__
dynamic_items[pattern] = item.__class__
elif item.is_dispatchable():
dispatch_info[(item.type.value, item.custom_id)] = item
is_fully_dynamic = False
return is_fully_dynamic
@classmethod
def from_component(cls, component: ContainerComponent) -> Self:
self = cls(
@ -360,15 +333,6 @@ class Container(Item[V]):
raise TypeError(f'expected Item not {item.__class__.__name__}')
self._children.append(item)
if item.is_dispatchable():
if getattr(item, '__discord_ui_section__', False):
self.__dispatchable.append(item.accessory) # type: ignore
elif getattr(item, '__discord_ui_action_row__', False):
self.__dispatchable.extend([i for i in item._children if i.is_dispatchable()]) # type: ignore
else:
self.__dispatchable.append(item)
is_layout_view = self._view and getattr(self._view, '__discord_ui_layout_view__', False)
if getattr(item, '__discord_ui_update_view__', False):
@ -400,17 +364,6 @@ class Container(Item[V]):
except ValueError:
pass
else:
if item.is_dispatchable():
if getattr(item, '__discord_ui_section__', False):
self._remove_dispatchable(item.accessory) # type: ignore
elif getattr(item, '__discord_ui_action_row__', False):
for c in item._children: # type: ignore
if not c.is_dispatchable():
continue
self._remove_dispatchable(c)
else:
self._remove_dispatchable(item)
if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
if getattr(item, '__discord_ui_update_view__', False):
self._view._total_children -= len(tuple(item.walk_children())) # type: ignore
@ -448,5 +401,4 @@ class Container(Item[V]):
if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
self._view._total_children -= sum(1 for _ in self.walk_children())
self._children.clear()
self.__dispatchable.clear()
return self

Loading…
Cancel
Save