diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 7dde6f5aa..dae01f300 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -74,7 +74,7 @@ jobs: if [ ${python_version:7:3} == "3.8" ]; then pip install -e ".[async]" pip install -e ".[adapter]" - pip install "pytype==2021.4.15" && pytype slack_bolt/ + pip install "pytype" && pytype slack_bolt/ fi - name: Run all tests for codecov (3.9 only) run: | diff --git a/slack_bolt/oauth/async_callback_options.py b/slack_bolt/oauth/async_callback_options.py index 6adb28cca..b24417239 100644 --- a/slack_bolt/oauth/async_callback_options.py +++ b/slack_bolt/oauth/async_callback_options.py @@ -91,8 +91,10 @@ def __init__( state_utils=state_utils, redirect_uri_page_renderer=redirect_uri_page_renderer, ) - self.success = self._success_handler - self.failure = self._failure_handler + # Note that pytype 2021.4.26 misunderstands these assignments. + # Thus, we put "type: ignore" for the following two lines + self.success = self._success_handler # type: ignore + self.failure = self._failure_handler # type: ignore # -------------------------- # Internal methods diff --git a/slack_bolt/oauth/async_oauth_settings.py b/slack_bolt/oauth/async_oauth_settings.py index 318842689..9580957e3 100644 --- a/slack_bolt/oauth/async_oauth_settings.py +++ b/slack_bolt/oauth/async_oauth_settings.py @@ -103,12 +103,14 @@ def __init__( logger: The logger that will be used internally """ # OAuth flow parameters/credentials - self.client_id = client_id or os.environ.get("SLACK_CLIENT_ID") - self.client_secret = client_secret or os.environ.get( - "SLACK_CLIENT_SECRET", None + client_id: Optional[str] = client_id or os.environ.get("SLACK_CLIENT_ID") + client_secret: Optional[str] = client_secret or os.environ.get( + "SLACK_CLIENT_SECRET" ) - if self.client_id is None or self.client_secret is None: + if client_id is None or client_secret is None: raise BoltError("Both client_id and client_secret are required") + self.client_id = client_id + self.client_secret = client_secret self.scopes = scopes or os.environ.get("SLACK_SCOPES", "").split(",") if isinstance(self.scopes, str): diff --git a/slack_bolt/oauth/oauth_settings.py b/slack_bolt/oauth/oauth_settings.py index 669aacac5..9ab100fd1 100644 --- a/slack_bolt/oauth/oauth_settings.py +++ b/slack_bolt/oauth/oauth_settings.py @@ -97,12 +97,14 @@ def __init__( state_expiration_seconds: The seconds that the state value is alive (Default: 600 seconds) logger: The logger that will be used internally """ - self.client_id = client_id or os.environ.get("SLACK_CLIENT_ID") - self.client_secret = client_secret or os.environ.get( - "SLACK_CLIENT_SECRET", None + client_id: Optional[str] = client_id or os.environ.get("SLACK_CLIENT_ID") + client_secret: Optional[str] = client_secret or os.environ.get( + "SLACK_CLIENT_SECRET" ) - if self.client_id is None or self.client_secret is None: + if client_id is None or client_secret is None: raise BoltError("Both client_id and client_secret are required") + self.client_id = client_id + self.client_secret = client_secret self.scopes = scopes or os.environ.get("SLACK_SCOPES", "").split(",") if isinstance(self.scopes, str): diff --git a/slack_bolt/request/async_request.py b/slack_bolt/request/async_request.py index 77ba23f6c..97ceab159 100644 --- a/slack_bolt/request/async_request.py +++ b/slack_bolt/request/async_request.py @@ -42,9 +42,21 @@ def __init__( context: The context in this request. mode: The mode used for this request. (either "http" or "socket_mode") """ - if mode == "http" and not isinstance(body, str): - raise BoltError(error_message_raw_body_required_in_http_mode()) - self.raw_body = body if mode == "http" else "" + + if mode == "http": + # HTTP Mode + if not isinstance(body, str): + raise BoltError(error_message_raw_body_required_in_http_mode()) + self.raw_body = body if body is not None else "" + else: + # Socket Mode + if body is not None and isinstance(body, str): + self.raw_body = body + else: + # We don't convert the dict value to str + # as doing so does not guarantee to keep the original structure/format. + self.raw_body = "" + self.query = parse_query(query) self.headers = build_normalized_headers(headers) self.content_type = extract_content_type(self.headers) @@ -57,7 +69,7 @@ def __init__( self.context = build_async_context( AsyncBoltContext(context if context else {}), self.body ) - self.lazy_only = self.headers.get("x-slack-bolt-lazy-only", [False])[0] + self.lazy_only = bool(self.headers.get("x-slack-bolt-lazy-only", [False])[0]) self.lazy_function_name = self.headers.get( "x-slack-bolt-lazy-function-name", [None] )[0] diff --git a/slack_bolt/request/request.py b/slack_bolt/request/request.py index 06b27142d..5d48d7a35 100644 --- a/slack_bolt/request/request.py +++ b/slack_bolt/request/request.py @@ -42,9 +42,20 @@ def __init__( context: The context in this request. mode: The mode used for this request. (either "http" or "socket_mode") """ - if mode == "http" and not isinstance(body, str): - raise BoltError(error_message_raw_body_required_in_http_mode()) - self.raw_body = body if mode == "http" else "" + if mode == "http": + # HTTP Mode + if not isinstance(body, str): + raise BoltError(error_message_raw_body_required_in_http_mode()) + self.raw_body = body if body is not None else "" + else: + # Socket Mode + if body is not None and isinstance(body, str): + self.raw_body = body + else: + # We don't convert the dict value to str + # as doing so does not guarantee to keep the original structure/format. + self.raw_body = "" + self.query = parse_query(query) self.headers = build_normalized_headers(headers) self.content_type = extract_content_type(self.headers) @@ -56,7 +67,7 @@ def __init__( raise BoltError(error_message_unknown_request_body_type()) self.context = build_context(BoltContext(context if context else {}), self.body) - self.lazy_only = self.headers.get("x-slack-bolt-lazy-only", [False])[0] + self.lazy_only = bool(self.headers.get("x-slack-bolt-lazy-only", [False])[0]) self.lazy_function_name = self.headers.get( "x-slack-bolt-lazy-function-name", [None] )[0]