Skip to content

Commit fe600b1

Browse files
feat: Add single item list_converter support (#1293)
* Add single item list_converter support * ci: correct from checks. * Fix defer_edit_origin not working * Revert "Fix defer_edit_origin not working" This reverts commit 6094cd7. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cdba57d commit fe600b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

interactions/client/utils/attr_converters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import inspect
22
import typing
33
from datetime import datetime
4-
from typing import Callable, Union
4+
from typing import Callable, Union, Any
55

66
from interactions.client.const import MISSING
77
from interactions.models.discord.timestamp import Timestamp
@@ -32,7 +32,11 @@ def timestamp_converter(value: Union[datetime, int, float, str]) -> Timestamp:
3232
def list_converter(converter) -> Callable[[list], list]:
3333
"""Converts a list of values to a list of converted values"""
3434

35-
def convert_action(value: list) -> list:
35+
def convert_action(value: Union[list, Any]) -> list:
36+
if not isinstance(value, list):
37+
"""If only one single item was passed (without a list), then we only convert that one item instead of throwing an exception."""
38+
return [converter(value)]
39+
3640
return [converter(element) for element in value]
3741

3842
return convert_action

0 commit comments

Comments
 (0)