Skip to content

Commit 5340ee3

Browse files
committed
Update WebClient to accept not only list but also tuple
1 parent dcf8e4a commit 5340ee3

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

slack_sdk/web/async_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"""A Python module for interacting with Slack's Web API."""
1111
import os
1212
from io import IOBase
13-
from typing import Union, Sequence, Optional, Dict
13+
from typing import Union, Sequence, Optional, Dict, Tuple
1414

1515
import slack_sdk.errors as e
1616
from slack_sdk.models.views import View
@@ -185,7 +185,7 @@ async def admin_conversations_invite(
185185
user_ids (str or list): The users to invite.
186186
"""
187187
kwargs.update({"channel_id": channel_id})
188-
if isinstance(user_ids, list):
188+
if isinstance(user_ids, (list, Tuple)):
189189
kwargs.update({"user_ids": ",".join(user_ids)})
190190
else:
191191
kwargs.update({"user_ids": user_ids})
@@ -523,7 +523,7 @@ async def admin_teams_settings_setDefaultChannels(
523523
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
524524
"""
525525
kwargs.update({"team_id": team_id})
526-
if isinstance(channel_ids, list):
526+
if isinstance(channel_ids, (list, Tuple)):
527527
kwargs.update({"channel_ids": ",".join(channel_ids)})
528528
else:
529529
kwargs.update({"channel_ids": channel_ids})
@@ -600,7 +600,7 @@ async def admin_usergroups_addChannels(
600600
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
601601
"""
602602
kwargs.update({"team_id": team_id, "usergroup_id": usergroup_id})
603-
if isinstance(channel_ids, list):
603+
if isinstance(channel_ids, (list, Tuple)):
604604
kwargs.update({"channel_ids": ",".join(channel_ids)})
605605
else:
606606
kwargs.update({"channel_ids": channel_ids})
@@ -618,7 +618,7 @@ async def admin_usergroups_addTeams(
618618
e.g. 'T12345678,T98765432' or ['T12345678', 'T98765432']
619619
"""
620620
kwargs.update({"usergroup_id": usergroup_id})
621-
if isinstance(team_ids, list):
621+
if isinstance(team_ids, (list, Tuple)):
622622
kwargs.update({"team_ids": ",".join(team_ids)})
623623
else:
624624
kwargs.update({"team_ids": team_ids})
@@ -645,7 +645,7 @@ async def admin_usergroups_removeChannels(
645645
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
646646
"""
647647
kwargs.update({"usergroup_id": usergroup_id})
648-
if isinstance(channel_ids, list):
648+
if isinstance(channel_ids, (list, Tuple)):
649649
kwargs.update({"channel_ids": ",".join(channel_ids)})
650650
else:
651651
kwargs.update({"channel_ids": channel_ids})
@@ -680,7 +680,7 @@ async def admin_users_invite(
680680
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
681681
"""
682682
kwargs.update({"team_id": team_id, "email": email})
683-
if isinstance(channel_ids, list):
683+
if isinstance(channel_ids, (list, Tuple)):
684684
kwargs.update({"channel_ids": ",".join(channel_ids)})
685685
else:
686686
kwargs.update({"channel_ids": channel_ids})
@@ -1233,7 +1233,7 @@ async def conversations_invite(
12331233
users (str or list): An list of user id's to invite. e.g. ['U2345678901', 'U3456789012']
12341234
"""
12351235
kwargs.update({"channel": channel})
1236-
if isinstance(users, list):
1236+
if isinstance(users, (list, Tuple)):
12371237
kwargs.update({"users": ",".join(users)})
12381238
else:
12391239
kwargs.update({"users": users})
@@ -1425,7 +1425,7 @@ async def dnd_teamInfo(
14251425
Args:
14261426
users (str or list): User IDs to fetch information e.g. 'U123,U234' or ["U123", "U234"]
14271427
"""
1428-
if isinstance(users, list):
1428+
if isinstance(users, (list, Tuple)):
14291429
kwargs.update({"users": ",".join(users)})
14301430
else:
14311431
kwargs.update({"users": users})
@@ -1524,7 +1524,7 @@ async def files_remote_share(
15241524
channels (str or list): Comma-separated list of channel IDs where the file will be shared.
15251525
e.g. ['C1234567890', 'C2345678901']
15261526
"""
1527-
if isinstance(channels, list):
1527+
if isinstance(channels, (list, Tuple)):
15281528
kwargs.update({"channels": ",".join(channels)})
15291529
else:
15301530
kwargs.update({"channels": channels})
@@ -1803,7 +1803,7 @@ async def migration_exchange(
18031803
users (str or list): A list of user ids, up to 400 per request.
18041804
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
18051805
"""
1806-
if isinstance(users, list):
1806+
if isinstance(users, (list, Tuple)):
18071807
kwargs.update({"users": ",".join(users)})
18081808
else:
18091809
kwargs.update({"users": users})
@@ -1853,7 +1853,7 @@ async def mpim_open(
18531853
is preserved whenever a MPIM group is returned.
18541854
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
18551855
"""
1856-
if isinstance(users, list):
1856+
if isinstance(users, (list, Tuple)):
18571857
kwargs.update({"users": ",".join(users)})
18581858
else:
18591859
kwargs.update({"users": users})
@@ -2203,7 +2203,7 @@ async def usergroups_users_update(
22032203
users for the User Group. e.g. ['U060R4BJ4', 'U060RNRCZ']
22042204
"""
22052205
kwargs.update({"usergroup": usergroup})
2206-
if isinstance(users, list):
2206+
if isinstance(users, (list, Tuple)):
22072207
kwargs.update({"users": ",".join(users)})
22082208
else:
22092209
kwargs.update({"users": users})

slack_sdk/web/client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""A Python module for interacting with Slack's Web API."""
22
import os
33
from io import IOBase
4-
from typing import Union, Sequence, Optional, Dict
4+
from typing import Union, Sequence, Optional, Dict, Tuple
55

66
import slack_sdk.errors as e
77
from slack_sdk.models.views import View
@@ -168,7 +168,7 @@ def admin_conversations_invite(
168168
user_ids (str or list): The users to invite.
169169
"""
170170
kwargs.update({"channel_id": channel_id})
171-
if isinstance(user_ids, list):
171+
if isinstance(user_ids, (list, Tuple)):
172172
kwargs.update({"user_ids": ",".join(user_ids)})
173173
else:
174174
kwargs.update({"user_ids": user_ids})
@@ -488,7 +488,7 @@ def admin_teams_settings_setDefaultChannels(
488488
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
489489
"""
490490
kwargs.update({"team_id": team_id})
491-
if isinstance(channel_ids, list):
491+
if isinstance(channel_ids, (list, Tuple)):
492492
kwargs.update({"channel_ids": ",".join(channel_ids)})
493493
else:
494494
kwargs.update({"channel_ids": channel_ids})
@@ -563,7 +563,7 @@ def admin_usergroups_addChannels(
563563
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
564564
"""
565565
kwargs.update({"team_id": team_id, "usergroup_id": usergroup_id})
566-
if isinstance(channel_ids, list):
566+
if isinstance(channel_ids, (list, Tuple)):
567567
kwargs.update({"channel_ids": ",".join(channel_ids)})
568568
else:
569569
kwargs.update({"channel_ids": channel_ids})
@@ -581,7 +581,7 @@ def admin_usergroups_addTeams(
581581
e.g. 'T12345678,T98765432' or ['T12345678', 'T98765432']
582582
"""
583583
kwargs.update({"usergroup_id": usergroup_id})
584-
if isinstance(team_ids, list):
584+
if isinstance(team_ids, (list, Tuple)):
585585
kwargs.update({"team_ids": ",".join(team_ids)})
586586
else:
587587
kwargs.update({"team_ids": team_ids})
@@ -608,7 +608,7 @@ def admin_usergroups_removeChannels(
608608
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
609609
"""
610610
kwargs.update({"usergroup_id": usergroup_id})
611-
if isinstance(channel_ids, list):
611+
if isinstance(channel_ids, (list, Tuple)):
612612
kwargs.update({"channel_ids": ",".join(channel_ids)})
613613
else:
614614
kwargs.update({"channel_ids": channel_ids})
@@ -643,7 +643,7 @@ def admin_users_invite(
643643
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
644644
"""
645645
kwargs.update({"team_id": team_id, "email": email})
646-
if isinstance(channel_ids, list):
646+
if isinstance(channel_ids, (list, Tuple)):
647647
kwargs.update({"channel_ids": ",".join(channel_ids)})
648648
else:
649649
kwargs.update({"channel_ids": channel_ids})
@@ -1162,7 +1162,7 @@ def conversations_invite(
11621162
users (str or list): An list of user id's to invite. e.g. ['U2345678901', 'U3456789012']
11631163
"""
11641164
kwargs.update({"channel": channel})
1165-
if isinstance(users, list):
1165+
if isinstance(users, (list, Tuple)):
11661166
kwargs.update({"users": ",".join(users)})
11671167
else:
11681168
kwargs.update({"users": users})
@@ -1336,7 +1336,7 @@ def dnd_teamInfo(self, users: Union[str, Sequence[str]], **kwargs) -> SlackRespo
13361336
Args:
13371337
users (str or list): User IDs to fetch information e.g. 'U123,U234' or ["U123", "U234"]
13381338
"""
1339-
if isinstance(users, list):
1339+
if isinstance(users, (list, Tuple)):
13401340
kwargs.update({"users": ",".join(users)})
13411341
else:
13421342
kwargs.update({"users": users})
@@ -1431,7 +1431,7 @@ def files_remote_share(
14311431
channels (str or list): Comma-separated list of channel IDs where the file will be shared.
14321432
e.g. ['C1234567890', 'C2345678901']
14331433
"""
1434-
if isinstance(channels, list):
1434+
if isinstance(channels, (list, Tuple)):
14351435
kwargs.update({"channels": ",".join(channels)})
14361436
else:
14371437
kwargs.update({"channels": channels})
@@ -1696,7 +1696,7 @@ def migration_exchange(
16961696
users (str or list): A list of user ids, up to 400 per request.
16971697
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
16981698
"""
1699-
if isinstance(users, list):
1699+
if isinstance(users, (list, Tuple)):
17001700
kwargs.update({"users": ",".join(users)})
17011701
else:
17021702
kwargs.update({"users": users})
@@ -1744,7 +1744,7 @@ def mpim_open(self, *, users: Union[str, Sequence[str]], **kwargs) -> SlackRespo
17441744
is preserved whenever a MPIM group is returned.
17451745
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
17461746
"""
1747-
if isinstance(users, list):
1747+
if isinstance(users, (list, Tuple)):
17481748
kwargs.update({"users": ",".join(users)})
17491749
else:
17501750
kwargs.update({"users": users})
@@ -2076,7 +2076,7 @@ def usergroups_users_update(
20762076
users for the User Group. e.g. ['U060R4BJ4', 'U060RNRCZ']
20772077
"""
20782078
kwargs.update({"usergroup": usergroup})
2079-
if isinstance(users, list):
2079+
if isinstance(users, (list, Tuple)):
20802080
kwargs.update({"users": ",".join(users)})
20812081
else:
20822082
kwargs.update({"users": users})

slack_sdk/web/legacy_client.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""A Python module for interacting with Slack's Web API."""
1313
import os
1414
from io import IOBase
15-
from typing import Union, Sequence, Optional, Dict
15+
from typing import Union, Sequence, Optional, Dict, Tuple
1616

1717
import slack_sdk.errors as e
1818
from slack_sdk.models.views import View
@@ -183,7 +183,7 @@ def admin_conversations_invite(
183183
user_ids (str or list): The users to invite.
184184
"""
185185
kwargs.update({"channel_id": channel_id})
186-
if isinstance(user_ids, list):
186+
if isinstance(user_ids, (list, Tuple)):
187187
kwargs.update({"user_ids": ",".join(user_ids)})
188188
else:
189189
kwargs.update({"user_ids": user_ids})
@@ -515,7 +515,7 @@ def admin_teams_settings_setDefaultChannels(
515515
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
516516
"""
517517
kwargs.update({"team_id": team_id})
518-
if isinstance(channel_ids, list):
518+
if isinstance(channel_ids, (list, Tuple)):
519519
kwargs.update({"channel_ids": ",".join(channel_ids)})
520520
else:
521521
kwargs.update({"channel_ids": channel_ids})
@@ -590,7 +590,7 @@ def admin_usergroups_addChannels(
590590
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
591591
"""
592592
kwargs.update({"team_id": team_id, "usergroup_id": usergroup_id})
593-
if isinstance(channel_ids, list):
593+
if isinstance(channel_ids, (list, Tuple)):
594594
kwargs.update({"channel_ids": ",".join(channel_ids)})
595595
else:
596596
kwargs.update({"channel_ids": channel_ids})
@@ -608,7 +608,7 @@ def admin_usergroups_addTeams(
608608
e.g. 'T12345678,T98765432' or ['T12345678', 'T98765432']
609609
"""
610610
kwargs.update({"usergroup_id": usergroup_id})
611-
if isinstance(team_ids, list):
611+
if isinstance(team_ids, (list, Tuple)):
612612
kwargs.update({"team_ids": ",".join(team_ids)})
613613
else:
614614
kwargs.update({"team_ids": team_ids})
@@ -635,7 +635,7 @@ def admin_usergroups_removeChannels(
635635
channel_ids (str or list): Comma separated string of channel IDs. e.g. 'C123,C234' or ['C123', 'C234']
636636
"""
637637
kwargs.update({"usergroup_id": usergroup_id})
638-
if isinstance(channel_ids, list):
638+
if isinstance(channel_ids, (list, Tuple)):
639639
kwargs.update({"channel_ids": ",".join(channel_ids)})
640640
else:
641641
kwargs.update({"channel_ids": channel_ids})
@@ -670,7 +670,7 @@ def admin_users_invite(
670670
At least one channel is required. e.g. ['C1A2B3C4D', 'C26Z25Y24']
671671
"""
672672
kwargs.update({"team_id": team_id, "email": email})
673-
if isinstance(channel_ids, list):
673+
if isinstance(channel_ids, (list, Tuple)):
674674
kwargs.update({"channel_ids": ",".join(channel_ids)})
675675
else:
676676
kwargs.update({"channel_ids": channel_ids})
@@ -1233,7 +1233,7 @@ def conversations_invite(
12331233
users (str or list): An list of user id's to invite. e.g. ['U2345678901', 'U3456789012']
12341234
"""
12351235
kwargs.update({"channel": channel})
1236-
if isinstance(users, list):
1236+
if isinstance(users, (list, Tuple)):
12371237
kwargs.update({"users": ",".join(users)})
12381238
else:
12391239
kwargs.update({"users": users})
@@ -1425,7 +1425,7 @@ def dnd_teamInfo(
14251425
Args:
14261426
users (str or list): User IDs to fetch information e.g. 'U123,U234' or ["U123", "U234"]
14271427
"""
1428-
if isinstance(users, list):
1428+
if isinstance(users, (list, Tuple)):
14291429
kwargs.update({"users": ",".join(users)})
14301430
else:
14311431
kwargs.update({"users": users})
@@ -1520,7 +1520,7 @@ def files_remote_share(
15201520
channels (str or list): Comma-separated list of channel IDs where the file will be shared.
15211521
e.g. ['C1234567890', 'C2345678901']
15221522
"""
1523-
if isinstance(channels, list):
1523+
if isinstance(channels, (list, Tuple)):
15241524
kwargs.update({"channels": ",".join(channels)})
15251525
else:
15261526
kwargs.update({"channels": channels})
@@ -1807,7 +1807,7 @@ def migration_exchange(
18071807
users (str or list): A list of user ids, up to 400 per request.
18081808
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
18091809
"""
1810-
if isinstance(users, list):
1810+
if isinstance(users, (list, Tuple)):
18111811
kwargs.update({"users": ",".join(users)})
18121812
else:
18131813
kwargs.update({"users": users})
@@ -1859,7 +1859,7 @@ def mpim_open(
18591859
is preserved whenever a MPIM group is returned.
18601860
e.g. ['W1234567890', 'U2345678901', 'U3456789012']
18611861
"""
1862-
if isinstance(users, list):
1862+
if isinstance(users, (list, Tuple)):
18631863
kwargs.update({"users": ",".join(users)})
18641864
else:
18651865
kwargs.update({"users": users})
@@ -2209,7 +2209,7 @@ def usergroups_users_update(
22092209
users for the User Group. e.g. ['U060R4BJ4', 'U060RNRCZ']
22102210
"""
22112211
kwargs.update({"usergroup": usergroup})
2212-
if isinstance(users, list):
2212+
if isinstance(users, (list, Tuple)):
22132213
kwargs.update({"users": ",".join(users)})
22142214
else:
22152215
kwargs.update({"users": users})

tests/slack_sdk_async/web/test_web_client_coverage.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ async def test_coverage(self):
102102
self.api_methods_to_call.remove(
103103
method(team_id="T123", channel_ids=["C123", "C234"])["method"]
104104
)
105+
# checking tuple compatibility as sample
106+
method(team_id="T123", channel_ids=("C123", "C234"))
105107
method(team_id="T123", channel_ids="C123,C234")
106108
await async_method(team_id="T123", channel_ids="C123,C234")
107109
elif method_name == "admin_teams_settings_setDescription":

0 commit comments

Comments
 (0)