Skip to content

Commit 64554bd

Browse files
health: move to mypy (#50)
* health: move to mypy * Why change if not broken
1 parent b3fa7e3 commit 64554bd

File tree

8 files changed

+26
-14
lines changed

8 files changed

+26
-14
lines changed

.github/maintainers_guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ To lint this project
7878
./scripts/lint.sh
7979
```
8080

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

8383
```zsh
84-
./scripts/run_pytype.sh
84+
./scripts/run_mypy.sh
8585
```
8686

8787
#### Develop Locally

.github/workflows/pytype.yml renamed to .github/workflows/mypy.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Run pytype validation
1+
name: Run mypy validation
22

33
on:
44
push:
@@ -11,13 +11,13 @@ jobs:
1111
timeout-minutes: 2
1212
strategy:
1313
matrix:
14-
python-version: ["3.11"]
14+
python-version: ["3.12"]
1515
steps:
1616
- uses: actions/checkout@v4
1717
- name: Set up Python ${{ matrix.python-version }}
1818
uses: actions/setup-python@v5
1919
with:
2020
python-version: ${{ matrix.python-version }}
21-
- name: Run pytype verification
21+
- name: Run mypy verification
2222
run: |
23-
./scripts/run_pytype.sh
23+
./scripts/run_mypy.sh

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ ENV/
109109
env.bak/
110110
venv.bak/
111111

112-
# pytype static type analyzer
112+
# static type analyzer
113113
.pytype/
114+
.mypy_cache/
114115

115116
# Cython debug symbols
116117
cython_debug/

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ log_file = "logs/pytest.log"
4848
log_file_level = "DEBUG"
4949
log_format = "%(asctime)s %(levelname)s %(message)s"
5050
log_date_format = "%Y-%m-%d %H:%M:%S"
51+
52+
[tool.mypy]
53+
files = "slack_cli_hooks/"
54+
force_union_syntax = true
55+
warn_unused_ignores = true

requirements/format.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
black
22
flake8>=5.0.4, <8;
3-
pytype; (python_version<"3.11" or python_version>"3.11")
4-
pytype==2024.4.11; python_version=="3.11"
3+
mypy>=1.11.1, <2

scripts/install_and_run_tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ then
1616
pytest -vv $1
1717
else
1818
pytest && \
19-
pytype slack_cli_hooks/
19+
mypy --config-file pyproject.toml
2020
fi

scripts/run_pytype.sh renamed to scripts/run_mypy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ set_prj_as_cwd
66

77
install_development_requirements
88

9-
pytype slack_cli_hooks/
9+
mypy --config-file pyproject.toml

slack_cli_hooks/hooks/check_update.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from http.client import HTTPResponse
44
import sys
55
from types import ModuleType
6-
from typing import Any, Dict, List, Optional
6+
from typing import Any, Dict, List, Optional, TypedDict
77
from urllib import request
88

99
import slack_bolt
@@ -18,6 +18,13 @@
1818

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

21+
ErrorType = TypedDict("ErrorType", {"message": str})
22+
OutputType = TypedDict(
23+
"OutputType",
24+
{"name": str, "url": str, "releases": List[Dict[str, Any]], "error": ErrorType},
25+
total=False,
26+
)
27+
2128

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

8592

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

9097
for dep in dependencies:

0 commit comments

Comments
 (0)