lib.data: make Field() immutable.

Mutability of Field isn't specified by the RFC and can cause issues
if the objects stored in Layout subclasses are mutated. There isn't
any reason to do that (the subclasses themselves are mutable and
handle that correctly), so disallow it.
This commit is contained in:
Catherine 2023-02-21 17:58:28 +00:00
parent e2f0519774
commit fcc4f54367
2 changed files with 15 additions and 17 deletions

View file

@ -59,6 +59,12 @@ class FieldTestCase(TestCase):
r"^Field offset must be a non-negative integer, not -1$"):
Field(unsigned(2), -1)
def test_immutable(self):
with self.assertRaises(AttributeError):
Field(1, 0).shape = unsigned(2)
with self.assertRaises(AttributeError):
Field(1, 0).offset = 1
class StructLayoutTestCase(TestCase):
def test_construct(self):