mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-12-22 06:25:12 +01:00
Check for 3D Arrays in check_keyboard_type
(#3514)
This commit is contained in:
parent
9782510779
commit
359232e6c7
3 changed files with 9 additions and 1 deletions
|
@ -31,7 +31,7 @@ from collections.abc import Sequence
|
|||
|
||||
|
||||
def check_keyboard_type(keyboard: object) -> bool:
|
||||
"""Checks if the keyboard provided is of the correct type - A list of lists.
|
||||
"""Checks if the keyboard provided is of the correct type - A sequence of sequences.
|
||||
Implicitly tested in the init-tests of `{Inline, Reply}KeyboardMarkup`
|
||||
"""
|
||||
# string and bytes may actually be used for ReplyKeyboardMarkup in which case each button
|
||||
|
@ -39,7 +39,11 @@ def check_keyboard_type(keyboard: object) -> bool:
|
|||
# allow it here.
|
||||
if not isinstance(keyboard, Sequence) or isinstance(keyboard, (str, bytes)):
|
||||
return False
|
||||
|
||||
for row in keyboard:
|
||||
if not isinstance(row, Sequence) or isinstance(row, (str, bytes)):
|
||||
return False
|
||||
for inner in row:
|
||||
if isinstance(inner, Sequence) and not isinstance(inner, str):
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -101,6 +101,8 @@ class TestInlineKeyboardMarkup:
|
|||
InlineKeyboardMarkup(["strings_are_not_allowed_in_the_rows_either"])
|
||||
with pytest.raises(ValueError):
|
||||
InlineKeyboardMarkup(InlineKeyboardButton("b1", "1"))
|
||||
with pytest.raises(ValueError):
|
||||
InlineKeyboardMarkup([[[InlineKeyboardButton("only_2d_array_is_allowed", "1")]]])
|
||||
|
||||
async def test_expected_values_empty_switch(self, inline_keyboard_markup, bot, monkeypatch):
|
||||
async def make_assertion(
|
||||
|
|
|
@ -116,6 +116,8 @@ class TestReplyKeyboardMarkup:
|
|||
ReplyKeyboardMarkup(["strings_are_not_allowed_in_the_rows_either"])
|
||||
with pytest.raises(ValueError):
|
||||
ReplyKeyboardMarkup(KeyboardButton("button1"))
|
||||
with pytest.raises(ValueError):
|
||||
ReplyKeyboardMarkup([[["button1"]]])
|
||||
|
||||
def test_to_dict(self, reply_keyboard_markup):
|
||||
reply_keyboard_markup_dict = reply_keyboard_markup.to_dict()
|
||||
|
|
Loading…
Reference in a new issue