From: Jérémie Galarneau Date: Fri, 15 Sep 2017 04:07:45 +0000 (-0400) Subject: Python bt2: remove type restriction on structure __setitem__ X-Git-Tag: v2.0.0-pre4~43 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=f987e50a1af0f55758c659cf19e0fdcef45ea065 Python bt2: remove type restriction on structure __setitem__ Signed-off-by: Jérémie Galarneau --- diff --git a/bindings/python/bt2/bt2/fields.py b/bindings/python/bt2/bt2/fields.py index 86323686..d34efdf7 100644 --- a/bindings/python/bt2/bt2/fields.py +++ b/bindings/python/bt2/bt2/fields.py @@ -465,16 +465,9 @@ class _StructureField(_ContainerField, collections.abc.MutableMapping): return _create_from_ptr(ptr) def __setitem__(self, key, value): - # we can only set numbers and strings - if not isinstance(value, (numbers.Number, str)): - raise TypeError('expecting number object or string') - - # raises if index is somehow invalid + # raises if key is somehow invalid field = self[key] - if not isinstance(field, (_NumericField, _StringField)): - raise TypeError('can only set the value of a number or string field') - # the field's property does the appropriate conversion or raises # the appropriate exception field.value = value diff --git a/tests/bindings/python/bt2/test_fields.py b/tests/bindings/python/bt2/test_fields.py index 3b0b424e..04ef0975 100644 --- a/tests/bindings/python/bt2/test_fields.py +++ b/tests/bindings/python/bt2/test_fields.py @@ -1356,7 +1356,8 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): struct_ft.append_field('A', elem_ft) struct_field = struct_ft() - with self.assertRaises(TypeError): + # Will fail on access to .items() of the value + with self.assertRaises(AttributeError): struct_field['A'] = 23 def test_setitem_none(self):