Python bt2: remove type restriction on structure __setitem__
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 15 Sep 2017 04:07:45 +0000 (00:07 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sat, 16 Sep 2017 02:24:30 +0000 (22:24 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/bt2/bt2/fields.py
tests/bindings/python/bt2/test_fields.py

index 86323686e4823572f8cb0ba7712d0bfbe14777b1..d34efdf7c636d145b959303f12b5ada5e35fa66b 100644 (file)
@@ -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
index 3b0b424edba734ed15c3e4cf706463d8440b56e0..04ef09750480b1f7b318a5e2201a07dd1e9a8889 100644 (file)
@@ -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):
This page took 0.026304 seconds and 4 git commands to generate.