mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Add GitHub annotations format for `--output`

Open edgarrmondragon opened this issue 1 year ago • 8 comments

Adds a new output format as GitHub Workflow commands, aka annotations.

Refs:

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

Closes https://github.com/python/mypy/issues/17612

edgarrmondragon avatar Sep 13 '24 22:09 edgarrmondragon

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Sep 13 '24 22:09 github-actions[bot]

I would love to see this merged, many people asked for it in https://github.com/python/mypy/issues/10816 and https://github.com/python/mypy/issues/14962 !

Seluj78 avatar Sep 17 '24 20:09 Seluj78

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Sep 17 '24 21:09 github-actions[bot]

I assume this no longer needs to be marked as a draft?

A5rocks avatar Sep 27 '24 14:09 A5rocks

I assume this no longer needs to be marked as a draft?

I've got a TODO comment in the diff that I want to address before opening the PR for review.

edgarrmondragon avatar Sep 27 '24 15:09 edgarrmondragon

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Sep 27 '24 17:09 github-actions[bot]

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Sep 27 '24 18:09 github-actions[bot]

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

github-actions[bot] avatar Oct 08 '24 06:10 github-actions[bot]

Diff from mypy_primer, showing the effect of this PR on open source code:

schemathesis (https://github.com/schemathesis/schemathesis)
-   File "/tmp/mypy_primer/old_mypy/venv/bin/mypy", line 8, in <module>
+   File "/tmp/mypy_primer/new_mypy/venv/bin/mypy", line 8, in <module>
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/__main__.py", line 15, in console_entry
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 119, in main
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 119, in main
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 203, in run_build
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/main.py", line 203, in run_build
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 191, in build
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 191, in build
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 267, in _build
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 267, in _build
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 2947, in dispatch
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 2947, in dispatch
-   File "/tmp/mypy_primer/old_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 976, in write_deps_cache
+   File "/tmp/mypy_primer/new_mypy/venv/lib/python3.12/site-packages/mypy/build.py", line 976, in write_deps_cache

github-actions[bot] avatar Jan 12 '25 21:01 github-actions[bot]

This would be a great feature; is it likely to make its way into 1.16?

lpulley avatar Feb 07 '25 15:02 lpulley

This would be a great feature; is it likely to make its way into 1.16?

Probably not. See https://github.com/python/mypy/pull/11396#issuecomment-2103437776.

edgarrmondragon avatar Feb 07 '25 18:02 edgarrmondragon

Since the output format of json has been merged, and it seems like they don't want to add another tool, can someone write something to convert from json to github format ?

Seluj78 avatar Jun 30 '25 09:06 Seluj78

Since the output format of json has been merged, and it seems like they don't want to add another tool, can someone write something to convert from json to github format ?

A simple one-liner you can add to your Github Workflow:

mypy . --output=json | jq -r '"::error title=Mypy issue,file=\(.file),line=\(.line),col=\(.column)::\(.message)"'

pdgendt avatar Jun 30 '25 10:06 pdgendt

Thanks ! I'm not skilled enough with jq, couldn't figure it out (Didn't try with AI).

Cheers @pdgendt

Seluj78 avatar Jun 30 '25 10:06 Seluj78

I agree with @JelleZijlstra that it would be preferable not to have to maintain multiple output formats. Perhaps as a compromise we could document the one-liner that @pdgendt created?

emmatyping avatar Aug 05 '25 01:08 emmatyping