haive.core.schema.compatibility.converters¶

Type conversion system for schema compatibility.

Classes¶

ConverterRegistry

Registry for type converters.

TypeConverter

Abstract base class for type converters.

Functions¶

get_converter_registry()

Get the global converter registry.

register_converter(converter)

Register a converter in the global registry.

Module Contents¶

class haive.core.schema.compatibility.converters.ConverterRegistry[source]¶

Registry for type converters.

Init .

can_convert(source_type, target_type)[source]¶

Check if conversion is possible.

Parameters:
  • source_type (type[Any])

  • target_type (type[Any])

Return type:

bool

convert(value, source_type, target_type)[source]¶

Convert a value using the best available converter.

Parameters:
  • value (Any)

  • source_type (type[Any])

  • target_type (type[Any])

Return type:

Any

get_converter(source_type, target_type)[source]¶

Get the best converter for a type pair.

Parameters:
  • source_type (type[Any])

  • target_type (type[Any])

Return type:

TypeConverter | None

list_converters()[source]¶

List all registered converter names.

Return type:

list[str]

register(converter)[source]¶

Register a type converter.

Parameters:

converter (TypeConverter)

Return type:

None

unregister(name)[source]¶

Unregister a type converter.

Parameters:

name (str)

Return type:

None

class haive.core.schema.compatibility.converters.TypeConverter[source]¶

Bases: abc.ABC

Abstract base class for type converters.

abstractmethod can_convert(source_type, target_type)[source]¶

Check if this converter can handle the conversion.

Parameters:
  • source_type (type[Any])

  • target_type (type[Any])

Return type:

bool

abstractmethod convert(value, context)[source]¶

Convert a value from source to target type.

Parameters:
Return type:

Any

estimate_quality(source_type, target_type)[source]¶

Estimate the quality of conversion.

Parameters:
  • source_type (type[Any])

  • target_type (type[Any])

Return type:

haive.core.schema.compatibility.types.ConversionQuality

property name: str¶
Abstractmethod:

Return type:

str

Unique name for this converter.

property priority: int¶

Priority for converter selection (higher = preferred).

Return type:

int

haive.core.schema.compatibility.converters.get_converter_registry()[source]¶

Get the global converter registry.

Return type:

ConverterRegistry

haive.core.schema.compatibility.converters.register_converter(converter)[source]¶

Register a converter in the global registry.

Parameters:

converter (TypeConverter)

Return type:

None