python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.27k stars 2.79k forks source link

Add a new output format option to print errors as GitHub Actions Workflow commands #17612

Open edgarrmondragon opened 2 months ago

edgarrmondragon commented 2 months ago

Feature

Add a new --output=github option to format errors as Workflow commands, similar to --output=json added in https://github.com/python/mypy/pull/11396.

Pitch

For example, for this output in JSON format

$ mypy src --output=json
{"file": "src/mylib/client.py", "line": 759, "column": 20, "message": "Argument 1 to \"export_responses\" of \"Client\" has incompatible type \"str\"; expected \"int\"", "hint": null, "code": "arg-type", "severity": "error"}

we'd get the following output in workflow command format

$ mypy src --output=json
::error file=src/mylib/client.py,line=759,col=20::(`arg-type`) Argument 1 to "export_responses" of "Client" has incompatible type "str"

Related:

wyardley commented 2 weeks ago

This would be super handy

webknjaz commented 2 weeks ago

@edgarrmondragon do you mean using the annotations feature?

wyardley commented 2 weeks ago

I'm not the person who opened the issue, but yes, I think this would support allowing annotations, similar to ruff check --output-format github or using pylint with the pylint-actions plugin.

edgarrmondragon commented 2 weeks ago

@edgarrmondragon do you mean using the annotations feature?

Yeah, these: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions

I'm not the person who opened the issue, but yes, I think this would support allowing annotations, similar to ruff check --output-format github or using pylint with the pylint-actions plugin.

Exactly!

edgarrmondragon commented 3 days ago

A PR is up if anyone's interested: https://github.com/python/mypy/pull/17771