Skip to content

Commit

Permalink
feat: Add single item list_converter support (#1293)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Speedcup and pre-commit-ci[bot] authored Mar 9, 2023
1 parent cdba57d commit fe600b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions interactions/client/utils/attr_converters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import inspect
import typing
from datetime import datetime
from typing import Callable, Union
from typing import Callable, Union, Any

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

def convert_action(value: list) -> list:
def convert_action(value: Union[list, Any]) -> list:
if not isinstance(value, list):
"""If only one single item was passed (without a list), then we only convert that one item instead of throwing an exception."""
return [converter(value)]

return [converter(element) for element in value]

return convert_action
Expand Down

0 comments on commit fe600b1

Please sign in to comment.