Prevent endless loop with buttons (#1626)

* fix: prevent endless loop with buttons

* test: added test for add w/o max width

* docs: added changelog record

* chore: explicit set max_width 0
This commit is contained in:
Oleg A. 2025-02-16 23:39:51 +03:00 committed by GitHub
parent 7b07338851
commit e17c84144d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 3 deletions

View file

@ -179,9 +179,12 @@ class KeyboardBuilder(Generic[ButtonType], ABC):
last_row.extend(head)
# Separate buttons to exclusive rows with max possible row width
while buttons:
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
markup.append(list(row))
if self.max_width > 0:
while buttons:
row, buttons = buttons[: self.max_width], buttons[self.max_width :]
markup.append(list(row))
else:
markup.append(list(buttons))
self._markup = markup
return self