Repository navigation
Conversation
nbQA prepends a CODE_SEPARATOR comment to every cell before handing the temporary Python file to the tool, and _get_line_numbers_for_mapping maps that line to cell line 0. A module-level diagnostic (D100, C0114) is reported by the tool on the first line of the file, so nbQA printed cell_1:0 - a line that does not exist, while every other line in the same output is 1-indexed. Map the separator line to the first line the user actually wrote. The three pydocstyle expectations that recorded cell_1:0 are updated accordingly. Closes nbQA-dev#821.
b155a0f to
fdf51c4
Compare
|
A note on the red marks here, because they say something other than what they look like. Neither this branch nor #907 has ever been tested. Both runs on the previous head were recorded as failures without starting a single job: Thirty days and thirty-two seconds apart, which is what happens to a fork run left in I have refreshed both branches onto current One thing to expect when they do run: #906 moves a cell's first line from 0 to 1 in reported positions; #907 keeps the tool's exit code when a notebook comes back unchanged. Both are small and independent of each other. |
Closes #821.
A diagnostic about the module as a whole comes back pointing at a line that does not exist:
F401is 1-indexed andD100is 0-indexed, in the same output.flake8behaves the same way. On the equivalent plain.pyfile both are at line 1, so the 0 does not come from the tool.Cause
Every cell in the temporary Python file starts with the
# %%NBQA-CELL-SEP...comment nbQA inserts itself, and_get_line_numbers_for_mappingmaps that line to cell line0. A module-level message is reported by the tool on line 1 of the file -- that is, on the separator -- so it is mapped back tocell_1:0.This maps the separator line to the first line the user actually wrote.
Existing expectations
Four
pydocstyleexpectations recordedcell_1:0 at module level-- one intests/tools/test_pydocstyle.pyand three intests/test_jupytext.py. They froze exactly the behaviour this issue is about, so they are updated tocell_1:1in the same commit. Flagging it explicitly rather than burying it in the diff: if you would rather keep the old numbering, this PR is the wrong change and I will close it.Tests
In
tests/test_map_python_line_to_nb_lines.py: a unit test on_get_line_numbers_for_mappingand an end-to-end check throughpylint --disable=all --enable=C0114. Both fail onmain.Test suite
3 failed, 118 passed, 3 skippedon this branch. The same threetests/tools/test_ruff_works.pyfailures are present onmain(newerruffoutput format) and are unrelated to this change.