Skip to content

Commit

Permalink
health: move to mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamBergamin committed Aug 16, 2024
1 parent b3fa7e3 commit edab713
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ To lint this project
./scripts/lint.sh
```

This project uses [pytype](https://google.github.io/pytype/) to check and infers types for your Python code.
This project uses [mypy](https://mypy.readthedocs.io/en/stable/index.html) to check and infers types for your Python code.

```zsh
./scripts/run_pytype.sh
./scripts/run_mypy.sh
```

#### Develop Locally
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pytype.yml → .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run pytype validation
name: Run mypy validation

on:
push:
Expand All @@ -11,13 +11,13 @@ jobs:
timeout-minutes: 2
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run pytype verification
- name: Run mypy verification
run: |
./scripts/run_pytype.sh
./scripts/run_mypy.sh
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ ENV/
env.bak/
venv.bak/

# pytype static type analyzer
# static type analyzer
.pytype/
.mypy_cache/

# Cython debug symbols
cython_debug/
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ log_file = "logs/pytest.log"
log_file_level = "DEBUG"
log_format = "%(asctime)s %(levelname)s %(message)s"
log_date_format = "%Y-%m-%d %H:%M:%S"

[tool.mypy]
files = "slack_cli_hooks/"
force_union_syntax = true
warn_unused_ignores = true
3 changes: 1 addition & 2 deletions requirements/format.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
black
flake8>=5.0.4, <8;
pytype; (python_version<"3.11" or python_version>"3.11")
pytype==2024.4.11; python_version=="3.11"
mypy>=1.11.1, <2
2 changes: 1 addition & 1 deletion scripts/install_and_run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ then
pytest -vv $1
else
pytest && \
pytype slack_cli_hooks/
mypy --config-file pyproject.toml
fi
2 changes: 1 addition & 1 deletion scripts/run_pytype.sh → scripts/run_mypy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ set_prj_as_cwd

install_development_requirements

pytype slack_cli_hooks/
mypy --config-file pyproject.toml
13 changes: 10 additions & 3 deletions slack_cli_hooks/hooks/check_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from http.client import HTTPResponse
import sys
from types import ModuleType
from typing import Any, Dict, List, Optional
from typing import Any, Dict, List, Optional, TypedDict
from urllib import request

import slack_bolt
Expand All @@ -18,6 +18,13 @@

DEPENDENCIES: List[ModuleType] = [slack_cli_hooks, slack_bolt, slack_sdk]

ErrorType = TypedDict("ErrorType", {"message": str})
OutputType = TypedDict(
"OutputType",
{"name": str, "url": str, "releases": List[Dict[str, Any]], "error": ErrorType},
total=False,
)


class Release:
def __init__(
Expand Down Expand Up @@ -83,8 +90,8 @@ def build_release(dependency: ModuleType) -> Release:
return Release(name=name, error={"message": str(e)})


def build_output(dependencies: List[ModuleType] = DEPENDENCIES) -> Dict[str, Any]:
output = {"name": "Slack Bolt", "url": "https://api.slack.com/automation/changelog", "releases": []}
def build_output(dependencies: List[ModuleType] = DEPENDENCIES) -> OutputType:
output: OutputType = {"name": "Slack Bolt", "url": "https://api.slack.com/automation/changelog", "releases": list()}
errors = []

for dep in dependencies:
Expand Down

0 comments on commit edab713

Please sign in to comment.