if len(field) == 2:
name, shape = field
direction = DIR_NONE
- if isinstance(shape, type) and issubclass(shape, Enum):
- shape = _enum_shape(shape)
if isinstance(shape, list):
shape = Layout.wrap(shape)
else:
if not isinstance(name, str):
raise TypeError("Field {!r} has invalid name: should be a string"
.format(field))
+ if isinstance(shape, type) and issubclass(shape, Enum):
+ shape = _enum_shape(shape)
if not isinstance(shape, (int, tuple, Layout)):
- raise TypeError("Field {!r} has invalid shape: should be an int, tuple, or list "
- "of fields of a nested record"
+ raise TypeError("Field {!r} has invalid shape: should be an int, tuple, Enum, or "
+ "list of fields of a nested record"
.format(field))
if name in self.fields:
raise NameError("Field {!r} has a name that is already present in the layout"
def test_enum_field(self):
layout = Layout.wrap([
("enum", UnsignedEnum),
+ ("enum_dir", UnsignedEnum, DIR_FANOUT),
])
self.assertEqual(layout["enum"], ((2, False), DIR_NONE))
+ self.assertEqual(layout["enum_dir"], ((2, False), DIR_FANOUT))
def test_slice_tuple(self):
layout = Layout.wrap([
def test_wrong_shape(self):
with self.assertRaises(TypeError,
- msg="Field ('a', 'x') has invalid shape: should be an int, tuple, or "
+ msg="Field ('a', 'x') has invalid shape: should be an int, tuple, Enum, or "
"list of fields of a nested record"):
Layout.wrap([("a", "x")])