Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI: strict mypy check in github actions #3107

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/mypy_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if [ "$(basename "$(pwd)")" = ".github" ]; then
cd ..
fi

xargs mypy --strict --follow-imports=silent --no-warn-unused-ignore --no-warn-return-any --install-types --non-interactive typings < .github/mypy_files.txt
Copy link
Member

Choose a reason for hiding this comment

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

If I do import schema in an options.py file, I get this:

worlds\witness\options.py:3: error: Skipping analyzing "schema": module is installed, but missing library stubs or py.typed marker [import-untyped]

That probably needs to be supressed? Not sure

Copy link
Collaborator Author

@beauxq beauxq Apr 7, 2024

Choose a reason for hiding this comment

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

We could add --disable-error-code=import-untyped
But another solution, that is more type safe, but also takes more work, is to make our own type stubs for libraries we use that don't have type information.

That's what the typings directory is for in Archipelago. I've been maintaining some kivy type stubs there for a while.
I improve them once in a while for the things I work on. We don't have typing for all of kivy, because that would be a ton of work. So I just add typing for the parts I work with.

2 changes: 2 additions & 0 deletions .github/mypy_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
worlds/AutoSNIClient.py
Patch.py
27 changes: 27 additions & 0 deletions .github/workflows/strict-type-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: type check

on:
pull_request:
paths:
- "**.py"
push:
paths:
- "**.py"

jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: "Install dependencies"
run: |
python -m pip install --upgrade pip mypy
python ModuleUpdate.py --append "WebHostLib/requirements.txt" --force --yes

- name: "mypy: strict check on specific files"
run: .github/mypy_check.sh
2 changes: 1 addition & 1 deletion ModuleUpdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def install_pkg_resources(yes=False):
subprocess.call([sys.executable, "-m", "pip", "install", "--upgrade", "setuptools"])


def update(yes=False, force=False):
def update(yes: bool = False, force: bool = False) -> None:
global update_ran
if not update_ran:
update_ran = True
Expand Down
2 changes: 1 addition & 1 deletion typings/kivy/uix/widget.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""" FillType_* is not a real kivy type - just something to fill unknown typing. """

from typing import Any, Optional, Protocol
from ..graphics import FillType_Drawable, FillType_Vec
from ..graphics.texture import FillType_Drawable, FillType_Vec


class FillType_BindCallback(Protocol):
Expand Down
2 changes: 1 addition & 1 deletion worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class SuffixIdentifier:
def __init__(self, *args: str):
self.suffixes = args

def __call__(self, path: str):
def __call__(self, path: str) -> bool:
if isinstance(path, str):
for suffix in self.suffixes:
if path.endswith(suffix):
Expand Down
Loading