Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/component/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,12 @@ def test_result(self):
self.roundtrip_simple('(result)', 'i32', [Variant('ok'), Variant('err')])


def test_variant_add_classes(self):
from wasmtime.component._types import VariantType, OptionType, ResultType, VariantLikeType
for cls in [VariantType, OptionType, ResultType]:
self.assertTrue(issubclass(cls, VariantLikeType))
self.assertEqual(cls.add_classes, VariantLikeType.add_classes)

# TODO: roundtrip future
# TODO: roundtrip stream
# TODO: roundtrip error-context
Expand Down
8 changes: 4 additions & 4 deletions wasmtime/component/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ class Variant:
case_test_cache: Set[type] = set()


class VariantLikeType:
class VariantLikeType(ValType):
@abstractmethod
def _cases(self) -> List[Tuple[str, Optional['ValType']]]:
pass
Expand Down Expand Up @@ -776,7 +776,7 @@ def _lift(self, tag: str, ptr: 'ctypes._Pointer[ffi.wasmtime_component_val_t]')
raise ValueError(f"tag {tag} not found in variant cases")


class VariantType(Managed["ctypes._Pointer[ffi.wasmtime_component_variant_type_t]"], ValType, VariantLikeType):
class VariantType(Managed["ctypes._Pointer[ffi.wasmtime_component_variant_type_t]"], VariantLikeType):
def _delete(self, ptr: "ctypes._Pointer[ffi.wasmtime_component_variant_type_t]") -> None:
ffi.wasmtime_component_variant_type_delete(ptr)

Expand Down Expand Up @@ -903,7 +903,7 @@ def convert_from_c(self, c: 'ffi.wasmtime_component_val_t') -> Any:
return ret


class OptionType(Managed["ctypes._Pointer[ffi.wasmtime_component_option_type_t]"], ValType, VariantLikeType):
class OptionType(Managed["ctypes._Pointer[ffi.wasmtime_component_option_type_t]"], VariantLikeType):
def _delete(self, ptr: "ctypes._Pointer[ffi.wasmtime_component_option_type_t]") -> None:
ffi.wasmtime_component_option_type_delete(ptr)

Expand Down Expand Up @@ -947,7 +947,7 @@ def convert_from_c(self, c: 'ffi.wasmtime_component_val_t') -> Any:



class ResultType(Managed["ctypes._Pointer[ffi.wasmtime_component_result_type_t]"], ValType, VariantLikeType):
class ResultType(Managed["ctypes._Pointer[ffi.wasmtime_component_result_type_t]"], VariantLikeType):
def _delete(self, ptr: "ctypes._Pointer[ffi.wasmtime_component_result_type_t]") -> None:
ffi.wasmtime_component_result_type_delete(ptr)

Expand Down
Loading