X Tutup
Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
15 changes: 13 additions & 2 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,19 @@ jobs:
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: ${{ env.LATEST_SUPPORTED_PY }}
- name: Run mypy verification
run: ./scripts/run_mypy.sh
- name: Install synchronous dependencies
run: |
pip install -U pip
pip install -U .
pip install -r requirements/tools.txt
- name: Type check synchronous modules
run: mypy --config-file pyproject.toml --exclude "async_|/adapter/"
- name: Install async and adapter dependencies
run: |
pip install -r requirements/async.txt
pip install -r requirements/adapter.txt
- name: Type check all modules
run: mypy --config-file pyproject.toml

unittest:
name: Unit tests
Expand Down
11 changes: 7 additions & 4 deletions slack_bolt/app/async_server.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import logging
from typing import Optional
from typing import Optional, TYPE_CHECKING

from aiohttp import web

from slack_bolt.adapter.aiohttp import to_bolt_request, to_aiohttp_response
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import get_boot_message

if TYPE_CHECKING:
from slack_bolt.app.async_app import AsyncApp


class AsyncSlackAppServer:
port: int
path: str
host: str
bolt_app: "AsyncApp" # type: ignore[name-defined]
bolt_app: "AsyncApp"
web_app: web.Application

def __init__(
self,
port: int,
path: str,
app: "AsyncApp", # type: ignore[name-defined]
app: "AsyncApp",
host: Optional[str] = None,
):
"""Standalone AIOHTTP Web Server.
Expand All @@ -34,7 +37,7 @@ def __init__(
self.port = port
self.path = path
self.host = host if host is not None else "0.0.0.0"
self.bolt_app: "AsyncApp" = app # type: ignore[name-defined]
self.bolt_app: "AsyncApp" = app
self.web_app = web.Application()
self._bolt_oauth_flow = self.bolt_app.oauth_flow
if self._bolt_oauth_flow:
Expand Down
7 changes: 5 additions & 2 deletions slack_bolt/context/async_context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, TYPE_CHECKING

from slack_sdk.web.async_client import AsyncWebClient

Expand All @@ -16,6 +16,9 @@
from slack_bolt.context.set_title.async_set_title import AsyncSetTitle
from slack_bolt.util.utils import create_copy

if TYPE_CHECKING:
from slack_bolt.listener.asyncio_runner import AsyncioListenerRunner


class AsyncBoltContext(BaseContext):
"""Context object associated with a request from Slack."""
Expand All @@ -42,7 +45,7 @@ def to_copyable(self) -> "AsyncBoltContext":

# The return type is intentionally string to avoid circular imports
@property
def listener_runner(self) -> "AsyncioListenerRunner": # type: ignore[name-defined]
def listener_runner(self) -> "AsyncioListenerRunner":
"""The properly configured listener_runner that is available for middleware/listeners."""
return self["listener_runner"]

Expand Down
7 changes: 5 additions & 2 deletions slack_bolt/context/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Optional, TYPE_CHECKING

from slack_sdk import WebClient

Expand All @@ -16,6 +16,9 @@
from slack_bolt.context.set_title import SetTitle
from slack_bolt.util.utils import create_copy

if TYPE_CHECKING:
from slack_bolt.listener.thread_runner import ThreadListenerRunner


class BoltContext(BaseContext):
"""Context object associated with a request from Slack."""
Expand Down Expand Up @@ -43,7 +46,7 @@ def to_copyable(self) -> "BoltContext":

# The return type is intentionally string to avoid circular imports
@property
def listener_runner(self) -> "ThreadListenerRunner": # type: ignore[name-defined]
def listener_runner(self) -> "ThreadListenerRunner":
"""The properly configured listener_runner that is available for middleware/listeners."""
return self["listener_runner"]

Expand Down
7 changes: 4 additions & 3 deletions slack_bolt/listener/async_listener_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ async def handle(
)
returned_response = await self.func(**kwargs)
if returned_response is not None and isinstance(returned_response, BoltResponse):
response.status = returned_response.status # type: ignore[union-attr]
response.headers = returned_response.headers # type: ignore[union-attr]
response.body = returned_response.body # type: ignore[union-attr]
assert response is not None, "response must be provided when returning a BoltResponse from an error handler"
response.status = returned_response.status
response.headers = returned_response.headers
response.body = returned_response.body


class AsyncDefaultListenerErrorHandler(AsyncListenerErrorHandler):
Expand Down
7 changes: 4 additions & 3 deletions slack_bolt/listener/listener_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def handle(
)
returned_response = self.func(**kwargs)
if returned_response is not None and isinstance(returned_response, BoltResponse):
response.status = returned_response.status # type: ignore[union-attr]
response.headers = returned_response.headers # type: ignore[union-attr]
response.body = returned_response.body # type: ignore[union-attr]
assert response is not None, "response must be provided when returning a BoltResponse from an error handler"
response.status = returned_response.status
response.headers = returned_response.headers
response.body = returned_response.body


class DefaultListenerErrorHandler(ListenerErrorHandler):
Expand Down
7 changes: 4 additions & 3 deletions slack_bolt/middleware/async_middleware_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ async def handle(
)
returned_response = await self.func(**kwargs)
if returned_response is not None and isinstance(returned_response, BoltResponse):
response.status = returned_response.status # type: ignore[union-attr]
response.headers = returned_response.headers # type: ignore[union-attr]
response.body = returned_response.body # type: ignore[union-attr]
assert response is not None, "response must be provided when returning a BoltResponse from an error handler"
response.status = returned_response.status
response.headers = returned_response.headers
response.body = returned_response.body


class AsyncDefaultMiddlewareErrorHandler(AsyncMiddlewareErrorHandler):
Expand Down
7 changes: 4 additions & 3 deletions slack_bolt/middleware/middleware_error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def handle(
)
returned_response = self.func(**kwargs)
if returned_response is not None and isinstance(returned_response, BoltResponse):
response.status = returned_response.status # type: ignore[union-attr]
response.headers = returned_response.headers # type: ignore[union-attr]
response.body = returned_response.body # type: ignore[union-attr]
assert response is not None, "response must be provided when returning a BoltResponse from an error handler"
response.status = returned_response.status
response.headers = returned_response.headers
response.body = returned_response.body


class DefaultMiddlewareErrorHandler(MiddlewareErrorHandler):
Expand Down
9 changes: 6 additions & 3 deletions slack_bolt/oauth/async_callback_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from logging import Logger
from typing import Optional, Callable, Awaitable
from typing import Optional, Callable, Awaitable, TYPE_CHECKING

from slack_sdk.oauth import RedirectUriPageRenderer, OAuthStateUtils
from slack_sdk.oauth.installation_store import Installation
Expand All @@ -9,14 +9,17 @@
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse

if TYPE_CHECKING:
from slack_bolt.oauth.async_oauth_settings import AsyncOAuthSettings


class AsyncSuccessArgs:
def __init__(
self,
*,
request: AsyncBoltRequest,
installation: Installation,
settings: "AsyncOAuthSettings", # type: ignore[name-defined]
settings: "AsyncOAuthSettings",
default: "AsyncCallbackOptions",
):
"""The arguments for a success function.
Expand All @@ -41,7 +44,7 @@ def __init__(
reason: str,
error: Optional[Exception] = None,
suggested_status_code: int,
settings: "AsyncOAuthSettings", # type: ignore[name-defined]
settings: "AsyncOAuthSettings",
default: "AsyncCallbackOptions",
):
"""The arguments for a failure function.
Expand Down
9 changes: 6 additions & 3 deletions slack_bolt/oauth/callback_options.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from logging import Logger
from typing import Optional, Callable
from typing import Optional, Callable, TYPE_CHECKING

from slack_sdk.oauth import RedirectUriPageRenderer, OAuthStateUtils
from slack_sdk.oauth.installation_store import Installation
Expand All @@ -9,14 +9,17 @@
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse

if TYPE_CHECKING:
from slack_bolt.oauth.oauth_settings import OAuthSettings


class SuccessArgs:
def __init__(
self,
*,
request: BoltRequest,
installation: Installation,
settings: "OAuthSettings", # type: ignore[name-defined]
settings: "OAuthSettings",
default: "CallbackOptions",
):
"""The arguments for a success function.
Expand All @@ -41,7 +44,7 @@ def __init__(
reason: str,
error: Optional[Exception] = None,
suggested_status_code: int,
settings: "OAuthSettings", # type: ignore[name-defined]
settings: "OAuthSettings",
default: "CallbackOptions",
):
"""The arguments for a failure function.
Expand Down
Loading
X Tutup