bt2: field.py: add index check in `selected_option_index` setter of `_VariantField`
[babeltrace.git] / src / bindings / python / bt2 / bt2 / field.py
index 4d31f8fa064517795ba0354399cea18c0301381c..56f94f0fb33b8fd4ed33db31059e5849742c8420 100644 (file)
@@ -559,12 +559,18 @@ class _OptionField(_Field):
 class _VariantField(_ContainerField, _Field):
     _NAME = 'Variant'
 
+    def _count(self):
+        return len(self.cls)
+
     @property
     def selected_option_index(self):
         return native_bt.field_variant_get_selected_option_field_index(self._ptr)
 
     @selected_option_index.setter
     def selected_option_index(self, index):
+        if index < 0 or index >= len(self):
+            raise IndexError('{} field object index is out of range'.format(self._NAME))
+
         native_bt.field_variant_select_option_field_by_index(self._ptr, index)
 
     @property
This page took 0.023542 seconds and 4 git commands to generate.