self.fields[field_name] = Signal(field_shape, name=concat(name, field_name))
def __getattr__(self, name):
- return self.fields[name]
+ return self[name]
def __getitem__(self, name):
- return self.fields[name]
+ try:
+ return self.fields[name]
+ except KeyError:
+ raise NameError("Record does not have a field '{}'. Did you mean one of: {}?"
+ .format(name, ", ".join(self.fields))) from None
def shape(self):
return sum(len(f) for f in self.fields.values()), False
self.assertEqual(repr(r), "(rec <unnamed> stb)")
self.assertEqual(r.stb.name, "stb")
+
+ def test_wrong_field(self):
+ r = Record([
+ ("stb", 1),
+ ("ack", 1),
+ ])
+ with self.assertRaises(NameError,
+ msg="Record does not have a field 'en'. Did you mean one of: stb, ack?"):
+ r.en