[unfinished, rfc]
Code in the same block after break, continue, return or raise can never be executed. Add a visitor that tracks when this is true and adds warnings to affected expressions.
brauch |
[unfinished, rfc]
Code in the same block after break, continue, return or raise can never be executed. Add a visitor that tracks when this is true and adds warnings to affected expressions.
It...seems to work.
TODO: unit tests, stress-testing, more looking at results.
Lint Skipped |
Unit Tests Skipped |
Even though we in principle have this kind of stuff in the control flow graph, this looks sane to me, tbh the control flow graph is a bit overdesigned for what one usually wants to do.
Hm, I think this actually needs to be merged into the declaration builder.
At the moment,
def foo(): if False: return 10
is given return type int when in fact it's equivalent to:
def foo(): if False: return 10 return None
And always returns NoneType.
i.e. the declaration builder must know whether the end of the function can be reached without hitting a return statement.
Not sure; if the nonsense code is deteced and marked with a warning, is it really a problem when the type inferred for it by static analysis is inaccurate?
In the example above, the code isn't nonsensical or warned about, but we get it wrong anyway. ;-)
The problem is that we ignore the implicit return None at the end of functions if there's /any/ explicit return statement, even if control-flow can still reach the end without hitting one.
Ah, I see what you mean -- you are right, if you want that feature. I'm fine with both variants, I think it's useful even without being in the declaration builder.