return self._spec_eq(other)
@property
- def field_class(self):
+ def cls(self):
field_class_ptr = native_bt.field_borrow_class_const(self._ptr)
assert field_class_ptr is not None
return bt2_field_class._create_field_class_from_ptr_and_get_ref(field_class_ptr)
return str(self.value_as_integer)
def __len__(self):
- return self.field_class.length
+ return self.cls.length
@functools.total_ordering
def _spec_eq(self, other):
try:
return self._value == self._extract_value(other)
- except:
+ except Exception:
return False
def __rmod__(self, other):
def _spec_eq(self, other):
try:
return self._value == self._value_to_str(other)
- except:
+ except Exception:
return False
def __lt__(self, other):
_NAME = 'Structure'
def _count(self):
- return len(self.field_class)
+ return len(self.cls)
def __setitem__(self, key, value):
# raises if key is somehow invalid
def __iter__(self):
# same name iterator
- return iter(self.field_class)
+ return iter(self.cls)
def _spec_eq(self, other):
if not isinstance(other, collections.abc.Mapping):
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