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
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
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