pythonjupyter-labpycodestyle

Automatically find the precise line in ipynb to fix indentation error for black


black ".\research\evaluation_detection.ipynb"

outputs

error: cannot format research\evaluation_detection.ipynb: unindent does not match any outer indentation level (<tokenize>, line 11)

Oh no! 💥 💔 💥
1 file failed to reformat.

The problem is that my file has lots of cells with line 11; there is only one level at the start of the file. What tool/script to use to resolve this codestyle exception breaking ability to commit.


Solution

  • jupyter nbconvert --to script ".\research\evaluation_detection.ipynb"
    

    gives more detailed error log that contains line

    raise IndentationError(
      File "<tokenize>", line 11
        n_face = len(face_obj)
    IndentationError: unindent does not match any outer indentation level
    

    by this line we can edit the original ipynb