You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
comparison-overlap error not triggered for booleans #11364
I think that this is by design. Bools are often used for things like debug flags that can typically be false, but it's still okay to write if DEBUG: print('something'). The idea is that the developer will temporarily modify the value of the flag during a debugging session if they want verbose logging.
if DEBUG == True: seems similar enough to if DEBUG: that they should probably use the same rules.
If this truly is intended then it is quite non-obvious, and not documented.
I propose that the current rules regarding ignoring bools only be applied to bools that are modified with always-X, and that they should be disabled for normal bools.
I think that as it stands it's an inconsistent feature, as debug options can also be integers or strings, and the benefits of catching true comparison-overlap errors far outweighs this hidden design in my opinion.
Activity
JukkaL commentedon Oct 20, 2021
I think that this is by design. Bools are often used for things like debug flags that can typically be false, but it's still okay to write
if DEBUG: print('something'). The idea is that the developer will temporarily modify the value of the flag during a debugging session if they want verbose logging.if DEBUG == True:seems similar enough toif DEBUG:that they should probably use the same rules.KotlinIsland commentedon Mar 2, 2022
(Gist)
There are a lot of simple situations that mypy doesn't seem to pick up on, all of these lines of code are suspect given the type annotations.
@JukkaL Do you mean debug flags that are used with
always-false/always-true(always-X) for the purpose of compilation optimization?This feature(fix?) would heavily clash with
always-Xas any variable modified by those flags would give false errors in every usage:If this truly is intended then it is quite non-obvious, and not documented.
I propose that the current rules regarding ignoring
bools only be applied tobools that are modified withalways-X, and that they should be disabled for normalbools.I think that as it stands it's an inconsistent feature, as debug options can also be integers or strings, and the benefits of catching true
comparison-overlaperrors far outweighs this hidden design in my opinion.KotlinIsland commentedon Mar 16, 2022
Researching this further, I have discovered that mypy already special cases artificially literal bools:
https://mypy-play.net/?mypy=latest&python=3.10&flags=warn-unreachable&gist=155eb9beccbfde903e2b3a5d61f0752e