hdl.rec: fix using Enum subclass as shape if direction is specified.

Also improves error messages.

Fixes #224.
This commit is contained in:
whitequark 2019-09-22 17:23:32 +00:00
parent 4c582ef609
commit 1976310bf0
2 changed files with 7 additions and 5 deletions

View file

@ -35,8 +35,6 @@ class Layout:
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:
@ -48,9 +46,11 @@ class Layout:
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"