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.
Hey, since the linked ticket is not public, could you share the status here? I’m currently trying to integrate mypy report to SonarQube Cloud with column information, and it doesn’t seem to work yet.
Here’s a sample of my mypy.txt report:
foobar.py:29:29:29:29: error: Function "builtins.any" is not valid as a type [valid-type]
foobar.py:29:29:29:29: note: Perhaps you meant "typing.Any" instead of "any"?
foobar.py:29:49:29:52: error: Incompatible default for argument "default" (default has type "None", argument has type "str") [assignment]
foobar.py:29:49:29:52: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
foobar.py:29:49:29:52: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
foobar.py:39:31:39:31: error: Function "builtins.any" is not valid as a type [valid-type]
foobar.py:39:31:39:31: note: Perhaps you meant "typing.Any" instead of "any"?
foobar.py:39:53:39:56: error: Incompatible default for argument "default" (default has type "None", argument has type "float") [assignment]
foobar.py:39:53:39:56: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
foobar.py:39:53:39:56: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
foobar.py:46:51:46:54: error: Incompatible default for argument "default" (default has type "None", argument has type "bool") [assignment]
foobar.py:46:51:46:54: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True
foobar.py:46:51:46:54: note: Use https://github.com/hauntsaninja/no_implicit_optional to automatically upgrade your codebase
The problem is resolved, it’s misconfig on our side. We have monorepo setup and the report contains relative file path not including the project root. Found out after adding -Dsonar.verbose=true flag. We run mypy with --show-absolute-path flag, and now it’s working as expected, including the column display