From 236355c2c6891fdf7ddcd2d841afe9898791f516 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 15 Sep 2017 00:07:45 -0400 Subject: [PATCH] Python bt2: remove type restriction on structure __setitem__ MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- bindings/python/bt2/bt2/fields.py | 9 +-------- tests/bindings/python/bt2/test_fields.py | 3 ++- 2 files changed, 3 insertions(+), 9 deletions(-) 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): -- 2.34.1