Closed pkolbus closed 4 years ago
I have a patch to fix this, but it touches ast.py within a few lines of #15 -- to avoid merge conflicts, I'll wait until that merges before creating the PR.
This is actually a huge surprise for me, but it seems like you're right. Thanks again!
According to the Cognitive Complexity specification, a fundamental increment is assessed for "
goto
, andbreak
orcontinue
to a label." (page 7 and section B1; emphasis mine). Simplebreak
andcontinue
do not receive an increment, as illuminated by the example foraddVersion()
in Appendix C, and by the justification that early exit tends to improve readability (page 7). (Further, the break in linear flow is already accounted for in theif
, asbreak
andcontinue
only make sense within a conditional.)The implementation assesses a structural increment for these constructs, causing complexity scores to be inflated. For example,
test_break_and_continue()
should be: