Whole file

Melevir/cognitive_complexity

The author described this change as Fix counting for binary logical operators. It counts as a record because the checks below fail on the code as it stood at aa428ca73 and pass on 3796e582e, with nothing else changed between the two runs.

Fix saved2020-07-05
Sharing licenceMIT · LICENSE
Change size+1 1

What the code was meant to do, written into the code itself as a save note

Fix counting for binary logical operators

The change

8585 return increment_by, 0, True
8686 elif isinstance(node, ast.BoolOp):
8787 inner_boolops_amount = len([n for n in ast.walk(node) if isinstance(n, ast.BoolOp)])
88- base_complexity = inner_boolops_amount * max(increment_by, 1)
88+ base_complexity = inner_boolops_amount
8989 return increment_by, base_complexity, False
9090 elif isinstance(node, (ast.Break, ast.Continue)):
9191 return increment_by, max(1, increment_by), True

The check that tells the two apart

failpass·tests/test_cognitive_complexity.py::test_nested_functions
failpass·tests/test_cognitive_complexity.py::test_real_function

Check file 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 itaa428ca731bc0461cc9f95956ff4816154495729
Broken version dated2020-07-05
Modulecognitive_complexity.utils.ast
Units changedprocess_node_itself
Fingerprinte9eff94957120177
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in Melevir/cognitive_complexity