Repository navigation
Refactor: reduce the cognitive complexity of _difference_bit_map (SonarCloud S3776) - #672
Merged
peacker merged 2 commits intoOct 23, 2026
Conversation
… cognitive complexity SonarCloud (python:S3776) flagged _difference_bit_map in the SMT quasidifferential model with a Cognitive Complexity of 19 against the 15 allowed. Move the nested SHIFT handling into a _shift_bit_map static helper, bringing it down to 10. The behaviour is unchanged.
test_save_as_latex_table, test_save_as_dataframe and test_save_as_json all exported into the default ./test_reports and each ended with clean_reports(), which deletes that folder. Run in parallel by xdist, one test could delete the folder while another was still writing into it (seen on the x86_64 runner as 'OSError: Cannot save file into a non-existent directory' in test_save_as_dataframe). Export and clean into a per-test tmp_path folder instead, as test_save_as_image already does.
peacker
merged commit Oct 23, 2026
ed2869d
into
feature/quasidifferential-implementation
6 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SonarCloud reports 1 new issue on #515:
The function is
SmtXorQuasidifferentialModel._difference_bit_map. Most of the score comes from the nestedif/forloops of its SHIFT case.Fix
Move the SHIFT handling into a new
_shift_bit_map(output_bit_size, shift_amount)static helper, with doctests for left and right shifts._difference_bit_mapdrops to a cognitive complexity of 10. The behaviour is unchanged.Verification (local)
smt_xor_quasidifferential_model.pypasses all 378 of its doctests, including the new_shift_bit_mapexamples.smt_xor_quasidifferential_model_test.pyand the*quasidifferential*tests intests/unit/components/, including the shift component).Also: race on
./test_reportsin the report export testsThe x86_64 pytest job failed on this PR in
report_test.py::test_save_as_dataframewithOSError: Cannot save file into a non-existent directory: '.../test_reports/...'. That's unrelated to the refactor above.test_save_as_latex_table,test_save_as_dataframeandtest_save_as_jsonall exported into the shared default./test_reportsand ended withclean_reports(), which deletes it. Under xdist one test could delete the folder while another was still writing. Each test now exports into, and cleans, its owntmp_pathfolder, astest_save_as_imagealready does. The default-directory behaviour stays covered by the*_uses_runtime_cwd_defaulttests.Checked locally: the dataframe, LaTeX and JSON exports write into the given folder, and
clean_reports(output_dir=...)removes it. The full tests weren't run locally, because dieharder is too slow on the dev machine and TensorFlow isn't installed there.🤖 Generated with Claude Code