Skip to content

Commit 9dcc0fb

Browse files
health: move to mypy (#1130)
* feat: use mypy instead of pytype * Minimal improvements * Improve error surfacing * Improve configuration and imports ignores * revert optional installation_store_bot_only * Add proper exception raising * Revert assert statements * Improve based on feedback * Improve error surfacing
1 parent ccbb541 commit 9dcc0fb

File tree

109 files changed

+540
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+540
-538
lines changed
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: 20
1212
strategy:
1313
matrix:
14-
python-version: ["3.9"]
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

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ filterwarnings = [
5050
"ignore:The loop argument is deprecated since Python 3.8, and scheduled for removal in Python 3.10.:DeprecationWarning",
5151
]
5252
asyncio_mode = "auto"
53+
54+
[tool.mypy]
55+
files = "slack_bolt/"
56+
force_union_syntax = true
57+
warn_unused_ignores = true
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# pip install -r requirements/testing_without_asyncio.txt
22
pytest>=6.2.5,<8.4 # https://github.com/tornadoweb/tornado/issues/3375
33
pytest-cov>=3,<6
4-
black==22.8.0 # Until we drop Python 3.6 support, we have to stay with this version

requirements/tools.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mypy==1.11.1
2+
flake8==6.0.0
3+
black==22.8.0 # Until we drop Python 3.6 support, we have to stay with this version

scripts/install_all_and_run_tests.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
script_dir=`dirname $0`
77
cd ${script_dir}/..
88
rm -rf ./slack_bolt.egg-info
9+
10+
# Update pip to prevent warnings
11+
pip install -U pip
12+
913
# The package causes a conflict with moto
1014
pip uninstall python-lambda
1115

@@ -32,10 +36,11 @@ else
3236
pip install -U -r requirements/testing.txt && \
3337
pip install -U -r requirements/adapter.txt && \
3438
pip install -U -r requirements/adapter_testing.txt && \
39+
pip install -r requirements/tools.txt && \
3540
# To avoid errors due to the old versions of click forced by Chalice
3641
pip install -U pip click && \
3742
black slack_bolt/ tests/ && \
43+
flake8 slack_bolt/ && flake8 examples/
3844
pytest && \
39-
pip install "pytype==2022.12.15" && \
40-
pytype slack_bolt/
45+
mypy --config-file pyproject.toml
4146
fi

scripts/run_flake8.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
script_dir=$(dirname $0)
55
cd ${script_dir}/.. && \
6-
pip install "flake8==6.0.0" && \
6+
pip install -r requirements/tools.txt && \
77
flake8 slack_bolt/ && flake8 examples/
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/bin/bash
2-
# ./scripts/run_pytype.sh
2+
# ./scripts/run_mypy.sh
33

44
script_dir=$(dirname $0)
55
cd ${script_dir}/.. && \
66
pip install .
77
pip install -r requirements/async.txt && \
88
pip install -r requirements/adapter.txt && \
9-
pip install "pytype==2022.12.15" && \
10-
pytype slack_bolt/
9+
pip install -r requirements/tools.txt && \
10+
mypy --config-file pyproject.toml

scripts/run_tests.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ then
1414
black slack_bolt/ tests/ && \
1515
pytest -vv $1
1616
else
17-
if [ ${python_version:0:3} == "3.8" ]
18-
then
19-
# pytype's behavior can be different in older Python versions
20-
black slack_bolt/ tests/ \
21-
&& pytest -vv \
22-
&& pip install -r requirements/adapter.txt \
23-
&& pip install -r requirements/adapter_testing.txt \
24-
&& pip install -U pip setuptools wheel \
25-
&& pip install -U pytype \
26-
&& pytype slack_bolt/
27-
else
2817
black slack_bolt/ tests/ && pytest
2918
fi
3019
fi

slack_bolt/adapter/aiohttp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async def to_bolt_request(request: web.Request) -> AsyncBoltRequest:
1010
return AsyncBoltRequest(
1111
body=await request.text(),
1212
query=request.query_string,
13-
headers=request.headers,
13+
headers=request.headers, # type: ignore[arg-type]
1414
)
1515

1616

@@ -33,7 +33,7 @@ async def to_aiohttp_response(bolt_resp: BoltResponse) -> web.Response:
3333
value=c.value,
3434
max_age=c.get("max-age"),
3535
expires=c.get("expires"),
36-
path=c.get("path"),
36+
path=c.get("path"), # type: ignore[arg-type]
3737
domain=c.get("domain"),
3838
secure=True,
3939
httponly=True,

slack_bolt/adapter/asgi/aiohttp/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from slack_bolt.oauth.async_oauth_flow import AsyncOAuthFlow
2-
31
from slack_bolt.adapter.asgi.http_request import AsgiHttpRequest
42
from slack_bolt.adapter.asgi.builtin import SlackRequestHandler
53

@@ -41,13 +39,11 @@ async def dispatch(self, request: AsgiHttpRequest) -> BoltResponse:
4139
)
4240

4341
async def handle_installation(self, request: AsgiHttpRequest) -> BoltResponse:
44-
oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
45-
return await oauth_flow.handle_installation(
42+
return await self.app.oauth_flow.handle_installation( # type: ignore[union-attr]
4643
AsyncBoltRequest(body=await request.get_raw_body(), query=request.query_string, headers=request.get_headers())
4744
)
4845

4946
async def handle_callback(self, request: AsgiHttpRequest) -> BoltResponse:
50-
oauth_flow: AsyncOAuthFlow = self.app.oauth_flow
51-
return await oauth_flow.handle_callback(
47+
return await self.app.oauth_flow.handle_callback( # type: ignore[union-attr]
5248
AsyncBoltRequest(body=await request.get_raw_body(), query=request.query_string, headers=request.get_headers())
5349
)

0 commit comments

Comments
 (0)