diff --git a/qalib/translators/__init__.py b/qalib/translators/__init__.py index 0b01d8d..ec2b800 100644 --- a/qalib/translators/__init__.py +++ b/qalib/translators/__init__.py @@ -9,8 +9,9 @@ M = TypeVar("M") N = TypeVar("N") P = ParamSpec("P") +I = TypeVar("I", bound=discord.ui.Item, covariant=True) -Callback = Callable[[discord.ui.Item, discord.Interaction], Awaitable[None]] +Callback = Callable[[I, discord.Interaction], Awaitable[None]] @dataclass @@ -74,7 +75,7 @@ def as_edit(self) -> EditContextMessage: suppress=self.suppress_embeds, delete_after=self.delete_after, allowed_mentions=self.allowed_mentions, - view=self.view + view=self.view, ) @@ -94,7 +95,7 @@ def as_edit(self) -> InteractionEditMessage: attachments=self.files, delete_after=self.delete_after, allowed_mentions=self.allowed_mentions, - view=self.view + view=self.view, ) diff --git a/qalib/translators/xml/embed.py b/qalib/translators/xml/embed.py index 4478946..76cc7c1 100644 --- a/qalib/translators/xml/embed.py +++ b/qalib/translators/xml/embed.py @@ -141,8 +141,10 @@ def colour(self) -> discord.Colour | int: Returns (Optional[int]): An integer containing the raw color. """ - return make_colour(self.get_element_text(self._raw_embed.find("color")) or self.get_element_text( - self._raw_embed.find("colour"))) + return make_colour( + self.get_element_text(self._raw_embed.find("color")) + or self.get_element_text(self._raw_embed.find("colour")) + ) class XMLEmbedAdapter(XMLBaseEmbedAdapter, EmbedAdapter): @@ -154,14 +156,18 @@ def fields(self) -> List[Field]: Returns (List[dict]): A list of dictionaries containing the raw fields. """ fields_element = self._raw_embed.find("fields") - return [] if fields_element is None else [ - { - "name": filter_tabs(self.get_element_text(field.find("name"))), - "value": filter_tabs(self.get_element_text(field.find("value"))), - "inline": field.get("inline", "").lower() == "true", - } - for field in fields_element.findall("field") - ] + return ( + [] + if fields_element is None + else [ + { + "name": filter_tabs(self.get_element_text(field.find("name"))), + "value": filter_tabs(self.get_element_text(field.find("value"))), + "inline": field.get("inline", "").lower() == "true", + } + for field in fields_element.findall("field") + ] + ) class XMLExpansiveEmbedAdapter(XMLBaseEmbedAdapter, ExpansiveEmbedAdapter): @@ -170,6 +176,10 @@ def __init__(self, embed: ElementTree.Element, page_number_key: Optional[str] = super().__init__(embed) ExpansiveEmbedAdapter.__init__(self, page_number_key) + @property + def fields(self) -> List[Field]: + return [self.field] + @property def field(self) -> Field: """Renders the field from an ElementTree.Element.