aiq.utils.type_converter#
Attributes#
Exceptions#
Common base class for all non-exit exceptions. |
Classes#
Functions#
|
Module Contents#
- logger#
- _T#
- exception ConvertException#
Bases:
Exception
Common base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- class TypeConverter(
- converters: list[collections.abc.Callable[[Any], Any]],
- parent: TypeConverter | None = None,
- Parameters:
converters – A list of single-argument converter callables annotated with their input param and return type.
parent – An optional parent TypeConverter for fallback.
- _global_initialized = False#
- _converters: collections.OrderedDict[type, collections.OrderedDict[type, collections.abc.Callable]]#
- _parent = None#
- add_converter(converter: collections.abc.Callable) None #
Registers a converter. Must have exactly one parameter and an annotated return type.
- try_convert(data, to_type: type[_T]) _T | None #
Attempts to convert
data
intoto_type
. Returns None if no path is found.
- convert(data, to_type: type[_T]) _T #
Converts or raises ValueError if no path is found. We also give the parent a chance if self fails.
- _try_direct_conversion(data, target_root_type: type) Any | None #
Tries direct conversion in this converter’s registry. If no match here, we forward to parent’s direct conversion for recursion up the chain.
- _try_indirect_convert(data, to_type: type[_T]) _T | None #
Attempt indirect conversion (DFS) in this converter. If no success, fallback to parent’s indirect attempt.
- class GlobalTypeConverter#
- _global_converter: TypeConverter#
- static get() TypeConverter #
- static register_converter(converter: collections.abc.Callable) None #
- _text_io_wrapper_to_string(data: io.TextIOWrapper) str #