Repository: pwndbg/pwndbg
Pull request: show `mypy` errors inline on PRs
<!-- Please make sure to read the testing and linting instructions at https://github.com/pwndbg/pwndbg/blob/dev/DEVELOPING.md before creating a PR -->

fixes #2053 


Problem statement:
Show lint errors as inline annotations in Github PRs
There are Github Actions that can run linters and report any violations inline on the PR itself (similar to the codecov comments we see now). This would be especially useful when we have new contributors who don't know to run the lint script, or struggle with fixing an issue. They would see the issue on the PR itself, and we could comment any suggestions there to help them.

I don't know exactly how to set this up, it would require some investigation.

Hints from issue discussion:
Ruff can automatically do this if we run with `--output-format github`. For `mypy`, we have to use another action: https://github.com/tsuyoshicho/action-mypy
Ruff support was implemented in #2070. Would appreciate it if someone could look into setting this up for `mypy`.

Commit message: Update .github/workflows/lint.yml

Co-authored-by: intrigus-lgtm <60750685+intrigus-lgtm@users.noreply.github.com>

Patch to review:
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 3e6cabc05dd..e271597f020 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -32,3 +32,17 @@ jobs:
       run: |
         git diff-index --quiet HEAD -- pwndbg tests
         ./lint.sh
+        
+    - name: Run mypy
+      uses: tsuyoshicho/action-mypy@v4
+      with:
+        github_token: ${{ secrets.GITHUB_TOKEN }}
+        # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
+        reporter: github-pr-review
+        # Change reporter level if you need.
+        # GitHub Status Check won't become failure with warning.
+        level: warning
+        # Change the current directory to run mypy command.
+        # mypy command reads setup.cfg or other settings file in this path.
+        execute_command: source ./.venv/bin/activate && mypy pwndbg
+
diff --git a/lint.sh b/lint.sh
index 748f64ceff8..71265610f43 100755
--- a/lint.sh
+++ b/lint.sh
@@ -80,4 +80,7 @@ fi
 # Checking minimum python version
 vermin -vvv --no-tips -t=3.8- --violations ./pwndbg/
 
-mypy pwndbg
+# mypy is run in a separate step on GitHub Actions
+if [[ -z "$GITHUB_ACTIONS" ]]; then
+    mypy pwndbg
+fi
diff --git a/pwndbg/ui.py b/pwndbg/ui.py
index af49cbdb9ff..7bafe0d969f 100644
--- a/pwndbg/ui.py
+++ b/pwndbg/ui.py
@@ -30,7 +30,7 @@
 
 
 @config.trigger(title_position)
-def check_title_position() -> None:
+def check_title_position() -> int:  # just a test to see if mypy inline reviews work
     valid_values = ["center", "left", "right"]
     if title_position not in valid_values:
         print(


Code review comments:
diff_hunk: @@ -32,3 +32,17 @@ jobs:
       run: |
         git diff-index --quiet HEAD -- pwndbg tests
         ./lint.sh
+        
+    - name: Run mypy
+      uses: tsuyoshicho/action-mypy@v4
+      with:
+        github_token: ${{ secrets.GITHUB_TOKEN }}
+        # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
+        reporter: github-pr-review
+        # Change reporter level if you need.
+        # GitHub Status Check won't become failure with warning.
+        level: warning
path: .github/workflows/lint.yml
text: @user1:
This should be "error", which matches the behavior before this change.

diff_hunk: @@ -32,3 +32,17 @@ jobs:
       run: |
         git diff-index --quiet HEAD -- pwndbg tests
         ./lint.sh
+        
+    - name: Run mypy
+      uses: tsuyoshicho/action-mypy@v4
+      with:
+        github_token: ${{ secrets.GITHUB_TOKEN }}
+        # Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
+        reporter: github-pr-review
path: .github/workflows/lint.yml
text: @user1:
What happens if you use `github-check` instead?
```suggestion
        reporter: github-check
```
or `github-pr-check`
```suggestion
        reporter: github-pr-check
```