Converters API Reference#
- class flare.converters.Converter(type: T)[source]#
-
Converters are used to convert types between a python object and string.
import flare import hikari class IntConverter(flare.Converter[int]): async def to_str(self, obj: int) -> str: return str(obj) async def from_str(self, obj: str) -> int: return int(obj) flare.add_converter(int, IntConverter) @flare.button(label="Button", style=hikari.ButtonStyle.PRIMARY) async def button( ctx: flare.MessageContext, # `IntConverter` will be used to serialize and deserialize this kwarg. number: int, ): ...
- type#
The type that is currently being serialized/deserialized. This will be different than the generic type if a subclass of the generic type is being serialized/deserialized.
- flare.converters.add_converter(t: Any, converter: type[Converter[Any]], *, supports_subclass: bool = False) None [source]#
Set a converter to be used for a certain type hint and the subclasses of the type hint.
- Parameters:
t – The type this converter supports.
converter – The converter object.
supports_subclass – If True, this converter will be used for subclasses of t.