Python: Mypy reports generated with --show-error-end ignore end line and end column

  • SonarQube Server, Enterprise Edition v10.8.1.
  • Deployed with Docker

I’m importing Mypy error reports into SonarQube for a Python project. By default, Mypy reports only include the line number of each error, but I am using the flag --show-error-end to Mypy to include start and end line and column numbers for each error in order to get more precise error highlighting in SonarQube.

Thus, my Mypy error reports look something like this:

src/example.py:19:31:19:46: error: Item "None" of "User | None" has no attribute "permissions"  [union-attr]
Found 1 error in 1 file (checked 1 source file)

This indicates an error that starts on line 19, column 31 and ends on line 19, column 46. However, when viewing the imported issues in SonarQube, only the first character of the erroneous code is highlighted, (line 19, col 31 in this case), but I would expect the entire range from col 31 to col 46 to get highlighted. If I instead omit the --show-error-end flag when generating the report, the entire line gets highlighted. This suggests that SonarQube overrides the end line and column numbers when importing the Mypy report.

This bug is also evident in the test suite for the Mypy importer in sonar-python. The test case issues_with_sonarqube_79_error_end() imports issues from mypy_output_show_error_end.txt which contains both line and column number for both start and end positions of each error, but the values for end column in the corresponding assertIssue() calls don’t match the actual end columns in the test report.

Hello @wieslander,
Thanks for reaching out.

This is indeed a bug in our implementation. I’ve created the ticket SONARPY-2745 to track the work.

The analyzer is currently completely ignoring the end column when importing mypy reports and is instead just adding one to the start column.

Best,
Sebastian Zumbrunn