Skip to content

Add GitHub annotations format for --output - #17771

Closed
edgarrmondragon wants to merge 1 commit into
python:masterfrom
edgarrmondragon:17612-github-annotations-output-format
Closed

edgarrmondragon wants to merge 1 commit into
python:masterfrom
edgarrmondragon:17612-github-annotations-output-format

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

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

Refs:

Closes #17612

@edgarrmondragon
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch 3 times, most recently from 21efb22 to 70c8feb Compare September 13, 2024 22:36
@github-actions

This comment has been minimized.

@Seluj78

Seluj78 commented Sep 17, 2024

Copy link
Copy Markdown

I would love to see this merged, many people asked for it in #10816 and #14962 !

@edgarrmondragon
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch from 70c8feb to b330d80 Compare September 17, 2024 21:09
@github-actions

This comment has been minimized.

@A5rocks

A5rocks commented Sep 27, 2024

Copy link
Copy Markdown
Collaborator

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

@edgarrmondragon

Copy link
Copy Markdown
Contributor Author

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
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch from b330d80 to e03e7f1 Compare September 27, 2024 17:35
@github-actions

This comment has been minimized.

@edgarrmondragon
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch from b335987 to fcdfa8f Compare September 27, 2024 18:05
Comment on lines +42 to +44
::notice file=main,line=12,col=12,title=Mypy (misc)::Revealed type is "Overload(def (), def (x: builtins.int))".
::error file=main,line=14,col=0,title=Mypy (call-overload)::No overload variant of "foo" matches argument type "str".%0A%0APossible overload variants:%0A def foo() -> None%0A def foo(x: int) -> None
::error file=main,line=17,col=0,title=Mypy (call-arg)::Too many arguments for "bar".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's how these look like in the diff view:

Screenshot 2024-09-27 at 12 07 56 p m

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks amazing!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing! We would like to use it in our github actions! Will this PR be merged soon?

@edgarrmondragon
edgarrmondragon marked this pull request as ready for review September 27, 2024 18:10
Comment thread mypy/main.py
general_group.add_argument(
"-O",
"--output",
metavar="FORMAT",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was preventing the choices from being displayed in the --help output

@github-actions

This comment has been minimized.

@edgarrmondragon
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch from fcdfa8f to f22bffa Compare October 8, 2024 06:25
@github-actions

This comment has been minimized.

@edgarrmondragon
edgarrmondragon force-pushed the 17612-github-annotations-output-format branch from f22bffa to 2a9c638 Compare January 12, 2025 21:17
@github-actions

Copy link
Copy Markdown
Contributor

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

@lpulley

lpulley commented Feb 7, 2025

Copy link
Copy Markdown

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

@edgarrmondragon

Copy link
Copy Markdown
Contributor Author

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

Probably not. See #11396 (comment).

@Seluj78

Seluj78 commented Jun 30, 2025

Copy link
Copy Markdown

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 ?

@pdgendt

pdgendt commented Jun 30, 2025

Copy link
Copy Markdown

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)"'

@Seluj78

Seluj78 commented Jun 30, 2025

Copy link
Copy Markdown

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

Cheers @pdgendt

@emmatyping

Copy link
Copy Markdown
Member

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?

@edgarrmondragon
edgarrmondragon deleted the 17612-github-annotations-output-format branch February 22, 2026 00:53
@cj81499

cj81499 commented Feb 22, 2026

Copy link
Copy Markdown

Bummed that this was closed, but I agree that documenting @pdgendt's one-liner would be highly valuable, with a much lower maintenance cost.

Any maintainers around to say if a contribution to do so would be welcomed? Any input on where it would belong in the docs?

@brianschubert

Copy link
Copy Markdown
Collaborator

FYI, there are some (rather low) limits on the number of annotations that GitHub will show. See e.g.

My understanding is that only up to 10 errors from a single mypy step can be show. That makes me wonder how useful it would be to document this, or if it might lead to user confusion due to some errors being hidden.

@A5rocks

A5rocks commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator

Bummed that this was closed, but I agree that documenting @pdgendt's one-liner would be highly valuable, with a much lower maintenance cost.

Any maintainers around to say if a contribution to do so would be welcomed? Any input on where it would belong in the docs?

Maybe https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-O or https://mypy.readthedocs.io/en/stable/faq.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

9 participants