Skip to content

Commit 8530e6b

Browse files
zimegClaude
andcommitted
refactor: simplify highlight_type passthrough by widening type annotation
Rely on the existing None-stripping logic in files_completeUploadExternal instead of conditionally building the dict. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
1 parent 6d1f1de commit 8530e6b

3 files changed

Lines changed: 6 additions & 24 deletions

File tree

slack_sdk/web/async_client.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4119,14 +4119,8 @@ async def files_upload_v2(
41194119
raise e.SlackRequestError(message)
41204120

41214121
# step3: files.completeUploadExternal with all the sets of (file_id + title)
4122-
complete_files = []
4123-
for f in files:
4124-
file_entry: Dict[str, str] = {"id": f["file_id"], "title": f["title"]}
4125-
if f.get("highlight_type") is not None:
4126-
file_entry["highlight_type"] = f["highlight_type"]
4127-
complete_files.append(file_entry)
41284122
completion = await self.files_completeUploadExternal(
4129-
files=complete_files,
4123+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
41304124
channel_id=channel,
41314125
channels=channels,
41324126
initial_comment=initial_comment,
@@ -4162,7 +4156,7 @@ async def files_getUploadURLExternal(
41624156
async def files_completeUploadExternal(
41634157
self,
41644158
*,
4165-
files: List[Dict[str, str]],
4159+
files: List[Dict[str, Optional[str]]],
41664160
channel_id: Optional[str] = None,
41674161
channels: Optional[List[str]] = None,
41684162
initial_comment: Optional[str] = None,

slack_sdk/web/client.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,14 +4109,8 @@ def files_upload_v2(
41094109
raise e.SlackRequestError(message)
41104110

41114111
# step3: files.completeUploadExternal with all the sets of (file_id + title)
4112-
complete_files = []
4113-
for f in files:
4114-
file_entry: Dict[str, str] = {"id": f["file_id"], "title": f["title"]}
4115-
if f.get("highlight_type") is not None:
4116-
file_entry["highlight_type"] = f["highlight_type"]
4117-
complete_files.append(file_entry)
41184112
completion = self.files_completeUploadExternal(
4119-
files=complete_files,
4113+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
41204114
channel_id=channel,
41214115
channels=channels,
41224116
initial_comment=initial_comment,
@@ -4152,7 +4146,7 @@ def files_getUploadURLExternal(
41524146
def files_completeUploadExternal(
41534147
self,
41544148
*,
4155-
files: List[Dict[str, str]],
4149+
files: List[Dict[str, Optional[str]]],
41564150
channel_id: Optional[str] = None,
41574151
channels: Optional[List[str]] = None,
41584152
initial_comment: Optional[str] = None,

slack_sdk/web/legacy_client.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4044,14 +4044,8 @@ def files_upload_v2(
40444044
raise e.SlackRequestError(message)
40454045

40464046
# step3: files.completeUploadExternal with all the sets of (file_id + title)
4047-
complete_files = []
4048-
for f in files:
4049-
file_entry: Dict[str, str] = {"id": f["file_id"], "title": f["title"]}
4050-
if f.get("highlight_type") is not None:
4051-
file_entry["highlight_type"] = f["highlight_type"]
4052-
complete_files.append(file_entry)
40534047
completion = self.files_completeUploadExternal(
4054-
files=complete_files,
4048+
files=[{"id": f["file_id"], "title": f["title"], "highlight_type": f.get("highlight_type")} for f in files],
40554049
channel_id=channel,
40564050
channels=channels,
40574051
initial_comment=initial_comment,
@@ -4087,7 +4081,7 @@ def files_getUploadURLExternal(
40874081
def files_completeUploadExternal(
40884082
self,
40894083
*,
4090-
files: List[Dict[str, str]],
4084+
files: List[Dict[str, Optional[str]]],
40914085
channel_id: Optional[str] = None,
40924086
channels: Optional[List[str]] = None,
40934087
initial_comment: Optional[str] = None,

0 commit comments

Comments
 (0)