Skip to content

Commit 1474b81

Browse files
chore: move to mypy
1 parent c7710f0 commit 1474b81

Some content is hidden

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

48 files changed

+217
-189
lines changed

.github/workflows/mypy.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: mypy validation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
timeout-minutes: 5
12+
strategy:
13+
matrix:
14+
python-version: ["3.13"]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Run mypy verification
22+
run: |
23+
./scripts/run_mypy.sh

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,4 @@ files = "slack_sdk/"
7676
exclude = ["slack_sdk/scim", "slack_sdk/rtm"]
7777
force_union_syntax = true
7878
warn_unused_ignores = true
79+
enable_error_code = "ignore-without-code"

scripts/run_mypy.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/bin/bash
22
# ./scripts/run_mypy.sh
33

4+
set -e
5+
46
script_dir=$(dirname $0)
5-
cd ${script_dir}/.. && \
6-
pip install .
7-
pip install -r requirements/testing.txt && \
8-
mypy --config-file pyproject.toml
7+
cd ${script_dir}/..
8+
9+
pip install -U pip setuptools wheel
10+
pip install -r requirements/testing.txt \
11+
-r requirements/optional.txt
12+
13+
mypy --config-file pyproject.toml

slack_sdk/audit_logs/v1/async_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ async def _perform_http_request(
279279
)
280280

281281
try:
282-
async with session.request(http_verb, url, **request_kwargs) as res: # type: ignore[arg-type, union-attr]
282+
async with session.request(http_verb, url, **request_kwargs) as res: # type: ignore[arg-type, union-attr] # noqa: E501
283283
try:
284284
response_body = await res.text()
285285
retry_response = RetryHttpResponse(

slack_sdk/audit_logs/v1/response.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AuditLogsResponse:
1313
body: Optional[Dict[str, Any]]
1414
typed_body: Optional[LogsResponse]
1515

16-
@property # type:ignore[no-redef]
16+
@property # type: ignore[no-redef]
1717
def typed_body(self) -> Optional[LogsResponse]:
1818
if self.body is None:
1919
return None

slack_sdk/http_retry/builtin_async_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ async def prepare_for_next_attempt_async(
8181
# This situation usually does not arise. Just in case.
8282
duration += random.random() # type: ignore[assignment]
8383
else:
84-
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[assignment, index]
84+
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[assignment, index] # noqa: E501
8585
await asyncio.sleep(duration)
8686
state.increment_current_attempt()
8787

slack_sdk/http_retry/builtin_handlers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def prepare_for_next_attempt(
8484
# This situation usually does not arise. Just in case.
8585
duration += random.random() # type: ignore[assignment]
8686
else:
87-
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[index, assignment]
87+
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[index, assignment] # noqa: E501
8888
time.sleep(duration)
8989
state.increment_current_attempt()
9090

slack_sdk/models/attachments/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def __init__(
4242
def name_or_url_present(self):
4343
return self.name is not None or self.url is not None
4444

45-
def to_dict(self) -> dict: # skipcq: PYL-W0221
45+
def to_dict(self) -> dict:
4646
json = super().to_dict()
4747
json["type"] = self.subtype
4848
return json
@@ -417,7 +417,7 @@ def author_link_without_author_name(self) -> bool:
417417
def author_link_without_author_icon(self) -> bool:
418418
return self.author_link is None or self.author_icon is not None
419419

420-
def to_dict(self) -> dict: # skipcq: PYL-W0221
420+
def to_dict(self) -> dict:
421421
json = super().to_dict()
422422
if self.fields is not None:
423423
json["fields"] = extract_json(self.fields)

slack_sdk/models/basic_objects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def get_non_null_attributes(self) -> dict:
4747
"""
4848

4949
def to_dict_compatible(value: Union[dict, list, object, tuple]) -> Union[dict, list, Any]:
50-
if isinstance(value, (list, tuple)): # skipcq: PYL-R1705
50+
if isinstance(value, (list, tuple)):
5151
return [to_dict_compatible(v) for v in value]
5252
else:
5353
to_dict = getattr(value, "to_dict", None)
54-
if to_dict and callable(to_dict): # skipcq: PYL-R1705
54+
if to_dict and callable(to_dict):
5555
return {k: to_dict_compatible(v) for k, v in value.to_dict().items()} # type: ignore[attr-defined]
5656
else:
5757
return value
@@ -69,7 +69,7 @@ def is_not_empty(self, key: str) -> bool:
6969
return True
7070

7171
has_len = getattr(value, "__len__", None) is not None
72-
if has_len: # skipcq: PYL-R1705
72+
if has_len:
7373
return len(value) > 0
7474
else:
7575
return value is not None
@@ -93,7 +93,7 @@ def to_dict(self, *args) -> dict:
9393

9494
def __repr__(self):
9595
dict_value = self.get_non_null_attributes()
96-
if dict_value: # skipcq: PYL-R1705
96+
if dict_value:
9797
return f"<slack_sdk.{self.__class__.__name__}: {dict_value}>"
9898
else:
9999
return self.__str__()

slack_sdk/models/blocks/basic_components.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TextObject(JsonObject):
2020
attributes = {"text", "type", "emoji"}
2121
logger = logging.getLogger(__name__)
2222

23-
def _subtype_warning(self): # skipcq: PYL-R0201
23+
def _subtype_warning(self):
2424
warnings.warn(
2525
"subtype is deprecated since slackclient 2.6.0, use type instead",
2626
DeprecationWarning,
@@ -36,17 +36,17 @@ def parse(
3636
text: Union[str, Dict[str, Any], "TextObject"],
3737
default_type: str = "mrkdwn",
3838
) -> Optional["TextObject"]:
39-
if not text: # skipcq: PYL-R1705
39+
if not text:
4040
return None
4141
elif isinstance(text, str):
42-
if default_type == PlainTextObject.type: # skipcq: PYL-R1705
42+
if default_type == PlainTextObject.type:
4343
return PlainTextObject.from_str(text)
4444
else:
4545
return MarkdownTextObject.from_str(text)
4646
elif isinstance(text, dict):
4747
d = copy.copy(text)
4848
t = d.pop("type")
49-
if t == PlainTextObject.type: # skipcq: PYL-R1705
49+
if t == PlainTextObject.type:
5050
return PlainTextObject(**d)
5151
else:
5252
return MarkdownTextObject(**d)
@@ -59,7 +59,7 @@ def parse(
5959
def __init__(
6060
self,
6161
text: str,
62-
type: Optional[str] = None, # skipcq: PYL-W0622
62+
type: Optional[str] = None,
6363
subtype: Optional[str] = None,
6464
emoji: Optional[bool] = None,
6565
**kwargs,
@@ -273,14 +273,14 @@ def parse_all(cls, options: Optional[Sequence[Union[Dict[str, Any], "Option"]]])
273273
cls.logger.warning(f"Unknown option object detected and skipped ({o})")
274274
return option_objects
275275

276-
def to_dict(self, option_type: str = "block") -> Dict[str, Any]: # skipcq: PYL-W0221
276+
def to_dict(self, option_type: str = "block") -> Dict[str, Any]:
277277
"""
278278
Different parent classes must call this with a valid value from OptionTypes -
279279
either "dialog", "action", or "block", so that JSON is returned in the
280280
correct shape.
281281
"""
282282
self.validate_json()
283-
if option_type == "dialog": # skipcq: PYL-R1705
283+
if option_type == "dialog":
284284
return {"label": self.label, "value": self.value}
285285
elif option_type == "action" or option_type == "attachment":
286286
# "action" can be confusing but it means a legacy message action in attachments
@@ -343,7 +343,7 @@ def __init__(
343343
options: A list of no more than 100 Option objects.
344344
""" # noqa prevent flake8 blowing up on the long URL
345345
# default_type=PlainTextObject.type is for backward-compatibility
346-
self._label: Optional[TextObject] = TextObject.parse(label, default_type=PlainTextObject.type) # type: ignore[arg-type]
346+
self._label: Optional[TextObject] = TextObject.parse(label, default_type=PlainTextObject.type) # type: ignore[arg-type] # noqa: E501
347347
self.label: Optional[str] = self._label.text if self._label else None
348348
self.options = Option.parse_all(options) # compatible with version 2.5
349349
show_unknown_key_warning(self, others)
@@ -373,10 +373,10 @@ def parse_all(
373373
cls.logger.warning(f"Unknown option group object detected and skipped ({o})")
374374
return option_group_objects
375375

376-
def to_dict(self, option_type: str = "block") -> Dict[str, Any]: # skipcq: PYL-W0221
376+
def to_dict(self, option_type: str = "block") -> Dict[str, Any]:
377377
self.validate_json()
378378
dict_options = [o.to_dict(option_type) for o in self.options] # type: ignore[union-attr]
379-
if option_type == "dialog": # skipcq: PYL-R1705
379+
if option_type == "dialog":
380380
return {
381381
"label": self.label,
382382
"options": dict_options,
@@ -405,7 +405,7 @@ class ConfirmObject(JsonObject):
405405
@classmethod
406406
def parse(cls, confirm: Union["ConfirmObject", Dict[str, Any]]):
407407
if confirm:
408-
if isinstance(confirm, ConfirmObject): # skipcq: PYL-R1705
408+
if isinstance(confirm, ConfirmObject):
409409
return confirm
410410
elif isinstance(confirm, dict):
411411
return ConfirmObject(**confirm)
@@ -462,8 +462,8 @@ def deny_length(self) -> bool:
462462
def _validate_confirm_style(self) -> bool:
463463
return self._style is None or self._style in ["primary", "danger"]
464464

465-
def to_dict(self, option_type: str = "block") -> Dict[str, Any]: # skipcq: PYL-W0221
466-
if option_type == "action": # skipcq: PYL-R1705
465+
def to_dict(self, option_type: str = "block") -> Dict[str, Any]:
466+
if option_type == "action":
467467
# deliberately skipping JSON validators here - can't find documentation
468468
# on actual limits here
469469
json: Dict[str, Union[str, dict]] = {
@@ -498,7 +498,7 @@ class DispatchActionConfig(JsonObject):
498498
@classmethod
499499
def parse(cls, config: Union["DispatchActionConfig", Dict[str, Any]]):
500500
if config:
501-
if isinstance(config, DispatchActionConfig): # skipcq: PYL-R1705
501+
if isinstance(config, DispatchActionConfig):
502502
return config
503503
elif isinstance(config, dict):
504504
return DispatchActionConfig(**config)
@@ -518,7 +518,7 @@ def __init__(
518518
"""
519519
self._trigger_actions_on = trigger_actions_on or []
520520

521-
def to_dict(self) -> Dict[str, Any]: # skipcq: PYL-W0221
521+
def to_dict(self) -> Dict[str, Any]:
522522
self.validate_json()
523523
json = {}
524524
if self._trigger_actions_on:
@@ -533,7 +533,7 @@ def __init__(self, *, url: str, customizable_input_parameters: Optional[List[Dic
533533
self._url = url
534534
self._customizable_input_parameters = customizable_input_parameters
535535

536-
def to_dict(self) -> Dict[str, Any]: # skipcq: PYL-W0221
536+
def to_dict(self) -> Dict[str, Any]:
537537
self.validate_json()
538538
json = {"url": self._url}
539539
if self._customizable_input_parameters is not None:
@@ -551,7 +551,7 @@ def __init__(
551551
):
552552
self._trigger = trigger
553553

554-
def to_dict(self) -> Dict[str, Any]: # skipcq: PYL-W0221
554+
def to_dict(self) -> Dict[str, Any]:
555555
self.validate_json()
556556
json = {}
557557
if isinstance(self._trigger, WorkflowTrigger):
@@ -580,7 +580,7 @@ def __init__(
580580
self._id = id
581581
self._url = url
582582

583-
def to_dict(self) -> Dict[str, Any]: # skipcq: PYL-W0221
583+
def to_dict(self) -> Dict[str, Any]:
584584
self.validate_json()
585585
json = {}
586586
if self._id is not None:

0 commit comments

Comments
 (0)