lib.enum: change shape mismatch warning category to SyntaxWarning
.
This commit is contained in:
parent
c1b9c64e10
commit
f77a335abf
|
@ -47,7 +47,7 @@ class EnumMeta(ShapeCastable, py_enum.EnumMeta):
|
||||||
message="Value of enumeration member {!r} is signed, but enumeration "
|
message="Value of enumeration member {!r} is signed, but enumeration "
|
||||||
"shape is {!r}" # the repr will be `unsigned(X)`
|
"shape is {!r}" # the repr will be `unsigned(X)`
|
||||||
.format(member, shape),
|
.format(member, shape),
|
||||||
category=RuntimeWarning,
|
category=SyntaxWarning,
|
||||||
stacklevel=2)
|
stacklevel=2)
|
||||||
elif (member_shape.width > shape.width or
|
elif (member_shape.width > shape.width or
|
||||||
member_shape.width == shape.width and
|
member_shape.width == shape.width and
|
||||||
|
@ -56,7 +56,7 @@ class EnumMeta(ShapeCastable, py_enum.EnumMeta):
|
||||||
message="Value of enumeration member {!r} will be truncated to "
|
message="Value of enumeration member {!r} will be truncated to "
|
||||||
"enumeration shape {!r}"
|
"enumeration shape {!r}"
|
||||||
.format(member, shape),
|
.format(member, shape),
|
||||||
category=RuntimeWarning,
|
category=SyntaxWarning,
|
||||||
stacklevel=2)
|
stacklevel=2)
|
||||||
else:
|
else:
|
||||||
# Shape is not provided explicitly. Behave the same as a standard enumeration;
|
# Shape is not provided explicitly. Behave the same as a standard enumeration;
|
||||||
|
|
|
@ -53,24 +53,24 @@ class EnumTestCase(FHDLTestCase):
|
||||||
self.assertEqual(Shape.cast(EnumD), signed(4))
|
self.assertEqual(Shape.cast(EnumD), signed(4))
|
||||||
|
|
||||||
def test_shape_explicit_wrong_signed_mismatch(self):
|
def test_shape_explicit_wrong_signed_mismatch(self):
|
||||||
with self.assertWarnsRegex(RuntimeWarning,
|
with self.assertWarnsRegex(SyntaxWarning,
|
||||||
r"^Value of enumeration member <EnumA\.A: -1> is signed, but enumeration "
|
r"^Value of enumeration member <EnumA\.A: -1> is signed, but enumeration "
|
||||||
r"shape is unsigned\(1\)$"):
|
r"shape is unsigned\(1\)$"):
|
||||||
class EnumA(Enum, shape=unsigned(1)):
|
class EnumA(Enum, shape=unsigned(1)):
|
||||||
A = -1
|
A = -1
|
||||||
|
|
||||||
def test_shape_explicit_wrong_too_wide(self):
|
def test_shape_explicit_wrong_too_wide(self):
|
||||||
with self.assertWarnsRegex(RuntimeWarning,
|
with self.assertWarnsRegex(SyntaxWarning,
|
||||||
r"^Value of enumeration member <EnumA\.A: 2> will be truncated to enumeration "
|
r"^Value of enumeration member <EnumA\.A: 2> will be truncated to enumeration "
|
||||||
r"shape unsigned\(1\)$"):
|
r"shape unsigned\(1\)$"):
|
||||||
class EnumA(Enum, shape=unsigned(1)):
|
class EnumA(Enum, shape=unsigned(1)):
|
||||||
A = 2
|
A = 2
|
||||||
with self.assertWarnsRegex(RuntimeWarning,
|
with self.assertWarnsRegex(SyntaxWarning,
|
||||||
r"^Value of enumeration member <EnumB\.A: 1> will be truncated to enumeration "
|
r"^Value of enumeration member <EnumB\.A: 1> will be truncated to enumeration "
|
||||||
r"shape signed\(1\)$"):
|
r"shape signed\(1\)$"):
|
||||||
class EnumB(Enum, shape=signed(1)):
|
class EnumB(Enum, shape=signed(1)):
|
||||||
A = 1
|
A = 1
|
||||||
with self.assertWarnsRegex(RuntimeWarning,
|
with self.assertWarnsRegex(SyntaxWarning,
|
||||||
r"^Value of enumeration member <EnumC\.A: -2> will be truncated to enumeration "
|
r"^Value of enumeration member <EnumC\.A: -2> will be truncated to enumeration "
|
||||||
r"shape signed\(1\)$"):
|
r"shape signed\(1\)$"):
|
||||||
class EnumC(Enum, shape=signed(1)):
|
class EnumC(Enum, shape=signed(1)):
|
||||||
|
|
Loading…
Reference in a new issue