Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark stars.* API methods as deprecated #1387

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions slack_sdk/models/blocks/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def parse(cls, block: Union[dict, "Block"]) -> Optional["Block"]:
def parse_all(cls, blocks: Optional[Sequence[Union[dict, "Block"]]]) -> List["Block"]:
return [cls.parse(b) for b in blocks or []] # type: ignore


# -------------------------------------------------
# Block Classes
# -------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions slack_sdk/web/async_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
_request_with_session,
) # type: ignore
from .async_slack_response import AsyncSlackResponse
from .deprecation import show_2020_01_deprecation
from .deprecation import show_deprecation_warning_if_any
from .internal_utils import (
convert_bool_to_0_or_1,
_build_req_args,
Expand Down Expand Up @@ -156,7 +156,7 @@ async def api_call( # skipcq: PYL-R1710
proxy=self.proxy,
)

show_2020_01_deprecation(api_method)
show_deprecation_warning_if_any(api_method)

return await self._send(
http_verb=http_verb,
Expand Down
4 changes: 2 additions & 2 deletions slack_sdk/web/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import slack_sdk.errors as err
from slack_sdk.errors import SlackRequestError
from .deprecation import show_2020_01_deprecation
from .deprecation import show_deprecation_warning_if_any
from .internal_utils import (
convert_bool_to_0_or_1,
get_user_agent,
Expand Down Expand Up @@ -152,7 +152,7 @@ def api_call( # skipcq: PYL-R1710
proxy=self.proxy,
)

show_2020_01_deprecation(api_method)
show_deprecation_warning_if_any(api_method)
return self._sync_send(api_url=api_url, req_args=req_args)

# =================================================================
Expand Down
14 changes: 13 additions & 1 deletion slack_sdk/web/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"admin.conversations.whitelist.",
]

deprecated_method_prefixes_2023_07 = ["stars."]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we want to include a comment to the changelog above this deprecation too? It's already included in the comment below so not a huge deal if not!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sadly, we don't have any workaround for this breaking change. So, I cannot think of any good comment for it


def show_2020_01_deprecation(method_name: str):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change!


def show_deprecation_warning_if_any(method_name: str):
"""Prints a warning if the given method is deprecated"""

skip_deprecation = os.environ.get("SLACKCLIENT_SKIP_DEPRECATION") # for unit tests etc.
Expand All @@ -20,6 +22,7 @@ def show_2020_01_deprecation(method_name: str):
if not method_name:
return

# 2020/01 conversations API deprecation
matched_prefixes = [prefix for prefix in deprecated_method_prefixes_2020_01 if method_name.startswith(prefix)]
if len(matched_prefixes) > 0:
message = (
Expand All @@ -28,3 +31,12 @@ def show_2020_01_deprecation(method_name: str):
"https://api.slack.com/changelog/2020-01-deprecating-antecedents-to-the-conversations-api"
)
warnings.warn(message)

# 2023/07 stars API deprecation
matched_prefixes = [prefix for prefix in deprecated_method_prefixes_2023_07 if method_name.startswith(prefix)]
if len(matched_prefixes) > 0:
message = (
f"{method_name} is deprecated. For more info, go to "
"https://api.slack.com/changelog/2023-07-its-later-already-for-stars-and-reminders"
)
warnings.warn(message)
4 changes: 2 additions & 2 deletions slack_sdk/web/legacy_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import slack_sdk.errors as err
from slack_sdk.errors import SlackRequestError
from .async_internal_utils import _files_to_data, _get_event_loop, _request_with_session
from .deprecation import show_2020_01_deprecation
from .deprecation import show_deprecation_warning_if_any
from .internal_utils import (
convert_bool_to_0_or_1,
get_user_agent,
Expand Down Expand Up @@ -161,7 +161,7 @@ def api_call( # skipcq: PYL-R1710
proxy=self.proxy,
)

show_2020_01_deprecation(api_method)
show_deprecation_warning_if_any(api_method)

if self.run_async or self.use_sync_aiohttp:
if self._event_loop is None:
Expand Down
28 changes: 28 additions & 0 deletions tests/slack_sdk/web/test_web_client_stars_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
import unittest
import pytest

from slack_sdk.web import WebClient
from tests.slack_sdk.web.mock_web_api_server import (
setup_mock_web_api_server,
cleanup_mock_web_api_server,
)


class TestWebClient(unittest.TestCase):
def setUp(self):
setup_mock_web_api_server(self)

def tearDown(self):
cleanup_mock_web_api_server(self)

# You can enable this test to verify if the warning can be printed as expected
@pytest.mark.skip()
def test_stars_deprecation(self):
env_value = os.environ.get("SLACKCLIENT_SKIP_DEPRECATION")
try:
os.environ.pop("SLACKCLIENT_SKIP_DEPRECATION")
client = WebClient(base_url="http://localhost:8888")
client.stars_list(token="xoxb-api_test")
finally:
os.environ.update({"SLACKCLIENT_SKIP_DEPRECATION": env_value})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to raise the following error if SLACKCLIENT_SKIP_DEPRECATION isn't set:

TypeError: str expected, not NoneType

Not a blocker IMO since the deprecation warning is correctly shown when setting this variable before running the test, just wanted to raise this!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good catch! will fix before merging it