Repository navigation
Conversation
nbQA resets output_code to 0 whenever the third-party tool rewrote the temporary Python file but the round-trip back into the notebook produced no change. That branch exists so that a formatter which only touched the temporary file is not reported as having changed the notebook, but it also swallows genuine failures: ruff check --fix can fix some violations, leave others unfixable and exit 1, and nbQA would report success. Only reset the exit code when the tool printed nothing at all. Closes nbQA-dev#872.
Eljees
force-pushed
the
fix/872-preserve-tool-exit-code
branch
from
August 14, 2026 07:05
55f4551 to
88c2b4a
Compare
This branch has not been deployed
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.
Closes #872.
nbQA resets
output_codeto0whenever the third-party tool rewrote the temporary Python file but the round-trip back into the notebook produced no change:That branch is there so a formatter which only touched the temporary file is not reported as having changed the notebook. It also swallows real failures, though:
ruff check --fixcan fix some violations, leave others unfixable and exit1, and nbQA still reports success -- so a pre-commit hook goes green over genuine errors.This keeps the
mutated = Falsereset and only zeroes the exit code when the tool printed nothing at all. If the tool printed something, there is something left to report, so its exit code survives.I also tried simply dropping the
output_code = 0reset. That breaks tools whose non-zero exit code means "I modified files" --blacken-docs, which is in this repo's ownrequirements-dev.txt, is one of them -- so nbQA would start failing on a notebook it had successfully left unchanged. Hence the narrower condition.Tests
Three tests in
tests/test_return_code.py, covering both directions of the new condition:mainwithassert 0 == 1)They use
unittest.mockrather than a notebook fixture on purpose: I could not find an input where a real tool leaves the notebook unchanged and exits non-zero. The condition is reachable, but hard to hit from the outside -- which is probably why it had no coverage.Test suite
3 failed, 119 passed, 3 skippedon this branch. The three failures are present onmainas well (tests/tools/test_ruff_works.py-- a newerruffprints diagnostics in a different format) and are untouched by this change.