Repository: Rapptz/discord.py
File: discord/ui/action_row.py (Python)

Code before:
            @row.button(label='A button!')
            async def row_button(self, interaction: discord.Interaction, button: discord.ui.Button):
                await interaction.response.send_message('You clicked a button!')

    Parameters
    ----------
    \*children: :class:`Item`
        The initial children of this action row.
    id: Optional[:class:`int`]
        The ID of this component. This must be unique across the view.
    """

    __action_row_children_items__: ClassVar[List[ItemCallbackType[Self, Any]]] = []
    __discord_ui_action_row__: ClassVar[bool] = True
    __item_repr_attributes__ = ('id',)

    def __init__(
        self,
        *children: Item[V],
        id: Optional[int] = None,
    ) -> None:
        super().__init__()
        self._children: List[Item[V]] = self._init_children()
        for child in children:
            self.add_item(child)
        self._weight: int = sum(i.width for i in self._children)

        if self._weight > 5:
            raise ValueError('maximum number of children exceeded')

        self.id = id

    def __init_subclass__(cls) -> None:
        super().__init_subclass__()

        children: Dict[str, ItemCallbackType[Self, Any]] = {}
        for base in reversed(cls.__mro__):
            for name, member in base.__dict__.items():
                if hasattr(member, '__discord_ui_model_type__'):
                    children[name] = member

        if len(children) > 5:
            raise TypeError('ActionRow cannot have more than 5 children')

        cls.__action_row_children_items__ = list(children.values())

    def __repr__(self) -> str:
        return f'<{self.__class__.__name__} children={len(self._children)}>'

    def _init_children(self) -> List[Item[Any]]:
        children = []

Review comment (bug):
`add_item` fails because it needs `self._weight` to exist
```suggestion
        self._weight: int = sum(i.width for i in self._children)
        for child in children:
            self.add_item(child)
```

Code after:
            @row.button(label='A button!')
            async def row_button(self, interaction: discord.Interaction, button: discord.ui.Button):
                await interaction.response.send_message('You clicked a button!')

    Parameters
    ----------
    \*children: :class:`Item`
        The initial children of this action row.
    id: Optional[:class:`int`]
        The ID of this component. This must be unique across the view.
    """

    __action_row_children_items__: ClassVar[List[ItemCallbackType[Self, Any]]] = []
    __discord_ui_action_row__: ClassVar[bool] = True
    __item_repr_attributes__ = ('id',)

    def __init__(
        self,
        *children: Item[V],
        id: Optional[int] = None,
    ) -> None:
        super().__init__()
        self._children: List[Item[V]] = self._init_children()
        self._weight: int = sum(i.width for i in self._children)
        for child in children:
            self.add_item(child)

        if self._weight > 5:
            raise ValueError('maximum number of children exceeded')

        self.id = id

    def __init_subclass__(cls) -> None:
        super().__init_subclass__()

        children: Dict[str, ItemCallbackType[Self, Any]] = {}
        for base in reversed(cls.__mro__):
            for name, member in base.__dict__.items():
                if hasattr(member, '__discord_ui_model_type__'):
                    children[name] = member

        if len(children) > 5:
            raise TypeError('ActionRow cannot have more than 5 children')

        cls.__action_row_children_items__ = list(children.values())

    def __repr__(self) -> str:
        return f'<{self.__class__.__name__} children={len(self._children)}>'

    def _init_children(self) -> List[Item[Any]]:
        children = []