Skip to content

Commit a30f930

Browse files
committed
Update the internals for deprecated parameters
1 parent 0247d64 commit a30f930

3 files changed

Lines changed: 55 additions & 28 deletions

File tree

slack_sdk/web/async_client.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3007,11 +3007,9 @@ async def files_upload_v2(
30073007
title: Optional[str] = None,
30083008
alt_txt: Optional[str] = None,
30093009
snippet_type: Optional[str] = None,
3010-
filetype: Optional[str] = None, # no longer supported
30113010
# To upload multiple files at a time
30123011
upload_files: Optional[List[Dict[str, Any]]] = None,
30133012
channel: Optional[str] = None,
3014-
channels: Optional[Union[str, Sequence[str]]] = None, # having n channels is no longer supported
30153013
initial_comment: Optional[str] = None,
30163014
thread_ts: Optional[str] = None,
30173015
**kwargs,
@@ -3025,13 +3023,24 @@ async def files_upload_v2(
30253023
raise e.SlackRequestError("Any of file, content, and upload_files must be specified.")
30263024
if file is not None and content is not None:
30273025
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
3028-
if channels is not None and (
3029-
(isinstance(channels, (list, Tuple)) and len(channels) > 1)
3030-
or (isinstance(channels, str) and len(channels.split(",")) > 1)
3031-
):
3032-
raise e.SlackRequestError("Sharing files with multiple channels is no longer supported")
3026+
3027+
# deprecated arguments:
3028+
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3029+
3030+
if channels is not None:
3031+
warnings.warn(
3032+
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3033+
"we recommend using the new channel parameter with a single str value instead for more clarity."
3034+
)
3035+
if (isinstance(channels, (list, Tuple)) and len(channels) > 1) or (
3036+
isinstance(channels, str) and len(channels.split(",")) > 1
3037+
):
3038+
raise e.SlackRequestError(
3039+
"Sharing files with multiple channels is no longer supported in v2. "
3040+
"Share files in each channel separately instead."
3041+
)
30333042
if filetype is not None:
3034-
warnings.warn("filetype is no longer supported. Please remove it from the arguments.")
3043+
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
30353044

30363045
# step1: files.getUploadURLExternal per file
30373046
files: List[Dict[str, Any]] = []
@@ -3060,8 +3069,8 @@ async def files_upload_v2(
30603069
token=kwargs.get("token"),
30613070
)
30623071
_validate_for_legacy_client(url_response)
3063-
f["file_id"] = url_response.get("file_id")
3064-
f["upload_url"] = url_response.get("upload_url")
3072+
f["file_id"] = url_response.get("file_id") # type: ignore
3073+
f["upload_url"] = url_response.get("upload_url") # type: ignore
30653074

30663075
# step2: "https://files.slack.com/upload/v1/..." per file
30673076
for f in files:

slack_sdk/web/client.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2998,11 +2998,9 @@ def files_upload_v2(
29982998
title: Optional[str] = None,
29992999
alt_txt: Optional[str] = None,
30003000
snippet_type: Optional[str] = None,
3001-
filetype: Optional[str] = None, # no longer supported
30023001
# To upload multiple files at a time
30033002
upload_files: Optional[List[Dict[str, Any]]] = None,
30043003
channel: Optional[str] = None,
3005-
channels: Optional[Union[str, Sequence[str]]] = None, # having n channels is no longer supported
30063004
initial_comment: Optional[str] = None,
30073005
thread_ts: Optional[str] = None,
30083006
**kwargs,
@@ -3016,13 +3014,24 @@ def files_upload_v2(
30163014
raise e.SlackRequestError("Any of file, content, and upload_files must be specified.")
30173015
if file is not None and content is not None:
30183016
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
3019-
if channels is not None and (
3020-
(isinstance(channels, (list, Tuple)) and len(channels) > 1)
3021-
or (isinstance(channels, str) and len(channels.split(",")) > 1)
3022-
):
3023-
raise e.SlackRequestError("Sharing files with multiple channels is no longer supported")
3017+
3018+
# deprecated arguments:
3019+
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3020+
3021+
if channels is not None:
3022+
warnings.warn(
3023+
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3024+
"we recommend using the new channel parameter with a single str value instead for more clarity."
3025+
)
3026+
if (isinstance(channels, (list, Tuple)) and len(channels) > 1) or (
3027+
isinstance(channels, str) and len(channels.split(",")) > 1
3028+
):
3029+
raise e.SlackRequestError(
3030+
"Sharing files with multiple channels is no longer supported in v2. "
3031+
"Share files in each channel separately instead."
3032+
)
30243033
if filetype is not None:
3025-
warnings.warn("filetype is no longer supported. Please remove it from the arguments.")
3034+
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
30263035

30273036
# step1: files.getUploadURLExternal per file
30283037
files: List[Dict[str, Any]] = []
@@ -3051,8 +3060,8 @@ def files_upload_v2(
30513060
token=kwargs.get("token"),
30523061
)
30533062
_validate_for_legacy_client(url_response)
3054-
f["file_id"] = url_response.get("file_id")
3055-
f["upload_url"] = url_response.get("upload_url")
3063+
f["file_id"] = url_response.get("file_id") # type: ignore
3064+
f["upload_url"] = url_response.get("upload_url") # type: ignore
30563065

30573066
# step2: "https://files.slack.com/upload/v1/..." per file
30583067
for f in files:

slack_sdk/web/legacy_client.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,11 +3009,9 @@ def files_upload_v2(
30093009
title: Optional[str] = None,
30103010
alt_txt: Optional[str] = None,
30113011
snippet_type: Optional[str] = None,
3012-
filetype: Optional[str] = None, # no longer supported
30133012
# To upload multiple files at a time
30143013
upload_files: Optional[List[Dict[str, Any]]] = None,
30153014
channel: Optional[str] = None,
3016-
channels: Optional[Union[str, Sequence[str]]] = None, # having n channels is no longer supported
30173015
initial_comment: Optional[str] = None,
30183016
thread_ts: Optional[str] = None,
30193017
**kwargs,
@@ -3027,13 +3025,24 @@ def files_upload_v2(
30273025
raise e.SlackRequestError("Any of file, content, and upload_files must be specified.")
30283026
if file is not None and content is not None:
30293027
raise e.SlackRequestError("You cannot specify both the file and the content argument.")
3030-
if channels is not None and (
3031-
(isinstance(channels, (list, Tuple)) and len(channels) > 1)
3032-
or (isinstance(channels, str) and len(channels.split(",")) > 1)
3033-
):
3034-
raise e.SlackRequestError("Sharing files with multiple channels is no longer supported")
3028+
3029+
# deprecated arguments:
3030+
channels, filetype = kwargs.get("channels"), kwargs.get("filetype")
3031+
3032+
if channels is not None:
3033+
warnings.warn(
3034+
"Although the channels parameter is still supported for smooth migration from legacy files.upload, "
3035+
"we recommend using the new channel parameter with a single str value instead for more clarity."
3036+
)
3037+
if (isinstance(channels, (list, Tuple)) and len(channels) > 1) or (
3038+
isinstance(channels, str) and len(channels.split(",")) > 1
3039+
):
3040+
raise e.SlackRequestError(
3041+
"Sharing files with multiple channels is no longer supported in v2. "
3042+
"Share files in each channel separately instead."
3043+
)
30353044
if filetype is not None:
3036-
warnings.warn("filetype is no longer supported. Please remove it from the arguments.")
3045+
warnings.warn("The filetype parameter is no longer supported. Please remove it from the arguments.")
30373046

30383047
# step1: files.getUploadURLExternal per file
30393048
files: List[Dict[str, Any]] = []

0 commit comments

Comments
 (0)