Whole file
Melevir/cognitive_complexity
The author described this change as “FIX #2: add penalty for break/continue”. It counts as a record because the check below fails on the code as it stood at 3b87123ad and passes on 85f0a1ab0, with nothing else changed between the two runs.
ProjectMelevir/cognitive_complexity
Fix saved2019-11-06
Sharing licenceMIT · LICENSE
Change size+2 −0
What the code was meant to do, written into the code itself as a save note
FIX #2: add penalty for break/continue
The change
| 34 | 34 | inner_boolops_amount = len([n for n in ast.walk(node) if isinstance(n, ast.BoolOp)]) | |
| 35 | 35 | base_complexity += inner_boolops_amount * increment_by | |
| 36 | 36 | should_iter_children = False | |
| 37 | + | elif isinstance(node, (ast.Break, ast.Continue)): | |
| 38 | + | base_complexity += max(1, increment_by) | |
| 37 | 39 | ||
| 38 | 40 | if should_iter_children: | |
| 39 | 41 | child_complexity += process_child_nodes( |
The check that tells the two apart
fail→pass·cognitive_complexity/tests/test_cognitive_complexity.py::test_break_and_continue
Check file cognitive_complexity/tests/test_cognitive_complexity.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it3b87123adc9cc2f8ab6d8c4b7dcc08bab9c51b2d
Broken version dated2019-11-06
Modulecognitive_complexity.api
Units changedget_cognitive_complexity_for_node
Fingerprintebba4abb1fa7bb5d
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.