Skip to content

Commit c7710f0

Browse files
Add support for mypy
1 parent 609c5a4 commit c7710f0

38 files changed

+184
-178
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ asyncio_mode = "auto"
7373

7474
[tool.mypy]
7575
files = "slack_sdk/"
76+
exclude = ["slack_sdk/scim", "slack_sdk/rtm"]
7677
force_union_syntax = true
7778
warn_unused_ignores = true
78-
exclude = ["slack_sdk/scim/*", "slack_sdk/rtm/*"]

slack_sdk/audit_logs/v1/async_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ async def _perform_http_request(
226226
headers: Dict[str, str],
227227
) -> AuditLogsResponse:
228228
if body_params is not None:
229-
body_params = json.dumps(body_params)
229+
body_params = json.dumps(body_params) # type: ignore[assignment]
230230
headers["Content-Type"] = "application/json;charset=utf-8"
231231

232232
session: Optional[ClientSession] = None
@@ -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]
282+
async with session.request(http_verb, url, **request_kwargs) as res: # type: ignore[arg-type, union-attr]
283283
try:
284284
response_body = await res.text()
285285
retry_response = RetryHttpResponse(
@@ -352,7 +352,7 @@ async def _perform_http_request(
352352

353353
if resp is not None:
354354
return resp
355-
raise last_error
355+
raise last_error # type: ignore[misc]
356356

357357
finally:
358358
if not use_running_session:

slack_sdk/audit_logs/v1/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def _perform_http_request(
218218
headers: Dict[str, str],
219219
) -> AuditLogsResponse:
220220
if body is not None:
221-
body = json.dumps(body)
221+
body = json.dumps(body) # type: ignore[assignment]
222222
headers["Content-Type"] = "application/json;charset=utf-8"
223223

224224
if self.logger.level <= logging.DEBUG:
@@ -230,7 +230,7 @@ def _perform_http_request(
230230
req = Request(
231231
method=http_verb,
232232
url=url,
233-
data=body.encode("utf-8") if body is not None else None,
233+
data=body.encode("utf-8") if body is not None else None, # type: ignore[attr-defined]
234234
headers=headers,
235235
)
236236
resp = None
@@ -328,7 +328,7 @@ def _perform_http_request(
328328

329329
if resp is not None:
330330
return resp
331-
raise last_error
331+
raise last_error # type: ignore[misc]
332332

333333
def _perform_http_request_internal(self, url: str, req: Request) -> AuditLogsResponse:
334334
opener: Optional[OpenerDirector] = None

slack_sdk/audit_logs/v1/logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ def __init__(
822822
self.rules_checked = None
823823
if rules_checked is not None:
824824
self.rules_checked = []
825-
for a in rules_checked:
825+
for a in rules_checked: # type: ignore[assignment]
826826
if isinstance(a, dict):
827827
self.rules_checked.append(AAARule(**a)) # type: ignore[arg-type]
828828
else:
@@ -1235,7 +1235,7 @@ def __init__(
12351235
provided: Optional[str] = None,
12361236
**kwargs,
12371237
) -> None:
1238-
self.entries = [Entry(**e) if isinstance(e, dict) else e for e in entries]
1238+
self.entries = [Entry(**e) if isinstance(e, dict) else e for e in entries] # type: ignore[union-attr]
12391239
self.response_metadata = (
12401240
ResponseMetadata(**response_metadata) if isinstance(response_metadata, dict) else response_metadata
12411241
)

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
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def prepare_for_next_attempt_async(
6868
error: Optional[Exception] = None,
6969
) -> None:
7070
if response is None:
71-
raise error
71+
raise error # type: ignore[misc]
7272

7373
state.next_attempt_requested = True
7474
retry_after_header_name: Optional[str] = None
@@ -79,9 +79,9 @@ async def prepare_for_next_attempt_async(
7979
duration = 1
8080
if retry_after_header_name is None:
8181
# This situation usually does not arise. Just in case.
82-
duration += random.random()
82+
duration += random.random() # type: ignore[assignment]
8383
else:
84-
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random()
84+
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[assignment, index]
8585
await asyncio.sleep(duration)
8686
state.increment_current_attempt()
8787

slack_sdk/http_retry/builtin_handlers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def prepare_for_next_attempt(
7171
error: Optional[Exception] = None,
7272
) -> None:
7373
if response is None:
74-
raise error
74+
raise error # type: ignore[misc]
7575

7676
state.next_attempt_requested = True
7777
retry_after_header_name: Optional[str] = None
@@ -82,9 +82,9 @@ def prepare_for_next_attempt(
8282
duration = 1
8383
if retry_after_header_name is None:
8484
# This situation usually does not arise. Just in case.
85-
duration += random.random()
85+
duration += random.random() # type: ignore[assignment]
8686
else:
87-
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random()
87+
duration = int(response.headers.get(retry_after_header_name)[0]) + random.random() # type: ignore[index, assignment]
8888
time.sleep(duration)
8989
state.increment_current_attempt()
9090

slack_sdk/models/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# NOTE: used only for legacy components - don't use this for Block Kit
1313
def extract_json(
1414
item_or_items: Union[JsonObject, Sequence[JsonObject]], *format_args
15-
) -> Union[Dict[Any, Any], List[Dict[Any, Any]]]:
15+
) -> Union[Dict[Any, Any], List[Dict[Any, Any]], Sequence[JsonObject]]:
1616
"""
1717
Given a sequence (or single item), attempt to call the to_dict() method on each
1818
item and return a plain list. If item is not the expected type, return it
@@ -24,11 +24,12 @@ def extract_json(
2424
method
2525
"""
2626
try:
27-
return [elem.to_dict(*format_args) if isinstance(elem, JsonObject) else elem for elem in item_or_items]
27+
return [
28+
elem.to_dict(*format_args) if isinstance(elem, JsonObject) else elem
29+
for elem in item_or_items # type: ignore[union-attr]
30+
]
2831
except TypeError: # not iterable, so try returning it as a single item
29-
return (
30-
item_or_items.to_dict(*format_args) if isinstance(item_or_items, JsonObject) else item_or_items # type: ignore
31-
)
32+
return item_or_items.to_dict(*format_args) if isinstance(item_or_items, JsonObject) else item_or_items
3233

3334

3435
def show_unknown_key_warning(name: Union[str, object], others: dict):

slack_sdk/models/attachments/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ActionExternalSelector(AbstractActionSelector):
212212
data_source = "external"
213213

214214
@property
215-
def attributes(self) -> Set[str]:
215+
def attributes(self) -> Set[str]: # type: ignore[override]
216216
return super().attributes.union({"min_query_length"})
217217

218218
def __init__(
@@ -469,7 +469,7 @@ def to_dict(self) -> dict:
469469

470470
class InteractiveAttachment(Attachment):
471471
@property
472-
def attributes(self) -> Set[str]:
472+
def attributes(self) -> Set[str]: # type: ignore[override]
473473
return super().attributes.union({"callback_id"})
474474

475475
actions_max_length = 5

slack_sdk/models/basic_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def wrapped_f(*args, **kwargs):
121121
if not func(*args, **kwargs):
122122
raise SlackObjectFormationError(self.message)
123123

124-
wrapped_f.validator = True
124+
wrapped_f.validator = True # type: ignore[attr-defined]
125125
return wrapped_f
126126

127127

0 commit comments

Comments
 (0)