Skip to content

Commit 9790bf3

Browse files
authored
Fix MRO for VariantLikeType.add_classes (#331)
1 parent 6dbbc50 commit 9790bf3

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

tests/component/test_func.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,12 @@ def test_result(self):
432432
self.roundtrip_simple('(result)', 'i32', [Variant('ok'), Variant('err')])
433433

434434

435+
def test_variant_add_classes(self):
436+
from wasmtime.component._types import VariantType, OptionType, ResultType, VariantLikeType
437+
for cls in [VariantType, OptionType, ResultType]:
438+
self.assertTrue(issubclass(cls, VariantLikeType))
439+
self.assertEqual(cls.add_classes, VariantLikeType.add_classes)
440+
435441
# TODO: roundtrip future
436442
# TODO: roundtrip stream
437443
# TODO: roundtrip error-context

wasmtime/component/_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ class Variant:
701701
case_test_cache: Set[type] = set()
702702

703703

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

778778

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

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

905905

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

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

948948

949949

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

0 commit comments

Comments
 (0)