Skip to content

Commit 357098c

Browse files
authored
Improve typing when using 'get' on API response (#1283)
1 parent c900682 commit 357098c

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

slack_sdk/web/async_slack_response.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""A Python module for interacting and consuming responses from Slack."""
22

33
import logging
4-
from typing import Union
4+
from typing import Any, Optional, TypeVar, Union, overload
55

66
import slack_sdk.errors as e
77
from .internal_utils import _next_cursor_is_present
88

9+
T = TypeVar("T")
10+
911

1012
class AsyncSlackResponse:
1113
"""An iterable container of response data.
@@ -159,6 +161,14 @@ async def __anext__(self):
159161
else:
160162
raise StopAsyncIteration
161163

164+
@overload
165+
def get(self, key: str, default: None = None) -> Optional[Any]:
166+
...
167+
168+
@overload
169+
def get(self, key: str, default: T) -> T:
170+
...
171+
162172
def get(self, key, default=None):
163173
"""Retrieves any key from the response data.
164174

slack_sdk/web/slack_response.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"""A Python module for interacting and consuming responses from Slack."""
22

33
import logging
4-
from typing import Union
4+
from typing import Any, Optional, TypeVar, Union, overload
55

66
import slack_sdk.errors as e
77
from .internal_utils import _next_cursor_is_present
88

9+
T = TypeVar("T")
10+
911

1012
class SlackResponse:
1113
"""An iterable container of response data.
@@ -156,6 +158,14 @@ def __next__(self):
156158
else:
157159
raise StopIteration
158160

161+
@overload
162+
def get(self, key: str, default: None = None) -> Optional[Any]:
163+
...
164+
165+
@overload
166+
def get(self, key: str, default: T) -> T:
167+
...
168+
159169
def get(self, key, default=None):
160170
"""Retrieves any key from the response data.
161171

0 commit comments

Comments
 (0)