hdl.dsl: reword m.If(~True) warning to be more clear.
Before this commit, it only suggested one thing (silencing it) and that's wrong almost all of the time, so suggest the right thing instead.
This commit is contained in:
parent
8854ca03ae
commit
99d205494a
|
@ -171,8 +171,9 @@ class Module(_ModuleBuilderRoot, Elaboratable):
|
||||||
if sign:
|
if sign:
|
||||||
warnings.warn("Signed values in If/Elif conditions usually result from inverting "
|
warnings.warn("Signed values in If/Elif conditions usually result from inverting "
|
||||||
"Python booleans with ~, which leads to unexpected results: ~True is "
|
"Python booleans with ~, which leads to unexpected results: ~True is "
|
||||||
"-2, which is truthful. "
|
"-2, which is truthful. Replace `~flag` with `not flag`. (If this is "
|
||||||
"(Silence this warning with `m.If(x)` → `m.If(x.bool())`.)",
|
"a false positive, silence this warning with "
|
||||||
|
"`m.If(x)` → `m.If(x.bool())`.)",
|
||||||
SyntaxWarning, stacklevel=4)
|
SyntaxWarning, stacklevel=4)
|
||||||
return cond
|
return cond
|
||||||
|
|
||||||
|
|
|
@ -273,7 +273,8 @@ class DSLTestCase(FHDLTestCase):
|
||||||
with self.assertWarns(SyntaxWarning,
|
with self.assertWarns(SyntaxWarning,
|
||||||
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
||||||
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
||||||
"truthful. (Silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
"truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
|
||||||
|
"silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
||||||
with m.If(~True):
|
with m.If(~True):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -284,7 +285,8 @@ class DSLTestCase(FHDLTestCase):
|
||||||
with self.assertWarns(SyntaxWarning,
|
with self.assertWarns(SyntaxWarning,
|
||||||
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
msg="Signed values in If/Elif conditions usually result from inverting Python "
|
||||||
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
"booleans with ~, which leads to unexpected results: ~True is -2, which is "
|
||||||
"truthful. (Silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
"truthful. Replace `~flag` with `not flag`. (If this is a false positive, "
|
||||||
|
"silence this warning with `m.If(x)` → `m.If(x.bool())`.)"):
|
||||||
with m.Elif(~True):
|
with m.Elif(~True):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue