From: whitequark Date: Sat, 3 Aug 2019 18:52:24 +0000 (+0000) Subject: hdl.dsl: reword m.If(~True) warning to be more clear. X-Git-Tag: locally_working~54 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=99d205494a8930eac8f7da85a9558dd7e7b933f6;p=nmigen.git 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. --- diff --git a/nmigen/hdl/dsl.py b/nmigen/hdl/dsl.py index e090b09..9a7d598 100644 --- a/nmigen/hdl/dsl.py +++ b/nmigen/hdl/dsl.py @@ -171,8 +171,9 @@ class Module(_ModuleBuilderRoot, Elaboratable): if sign: warnings.warn("Signed values in If/Elif conditions usually result from inverting " "Python booleans with ~, which leads to unexpected results: ~True is " - "-2, which is truthful. " - "(Silence this warning with `m.If(x)` → `m.If(x.bool())`.)", + "-2, which is truthful. Replace `~flag` with `not flag`. (If this is " + "a false positive, silence this warning with " + "`m.If(x)` → `m.If(x.bool())`.)", SyntaxWarning, stacklevel=4) return cond diff --git a/nmigen/test/test_hdl_dsl.py b/nmigen/test/test_hdl_dsl.py index 0ff7fef..1da5a6a 100644 --- a/nmigen/test/test_hdl_dsl.py +++ b/nmigen/test/test_hdl_dsl.py @@ -273,7 +273,8 @@ class DSLTestCase(FHDLTestCase): with self.assertWarns(SyntaxWarning, msg="Signed values in If/Elif conditions usually result from inverting Python " "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): pass @@ -284,7 +285,8 @@ class DSLTestCase(FHDLTestCase): with self.assertWarns(SyntaxWarning, msg="Signed values in If/Elif conditions usually result from inverting Python " "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): pass