Skip to content
Open
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
3 changes: 1 addition & 2 deletions slack/web/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ def _get_user_agent():
v=sys.version_info
)
system_info = "{0}/{1}".format(platform.system(), platform.release())
user_agent_string = " ".join([python_version, client, system_info])
return user_agent_string
return " ".join([python_version, client, system_info])
Copy link
Author

Choose a reason for hiding this comment

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

Function BaseClient._get_user_agent refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


@staticmethod
def validate_slack_signature(
Expand Down
13 changes: 5 additions & 8 deletions slack/web/classes/dialog_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,13 @@ def data_source_valid(self):

def to_dict(self) -> dict:
json = super().to_dict()
if self.data_source == "external":
if isinstance(self.value, Option):
if isinstance(self.value, Option):
if self.data_source == "external":
json["selected_options"] = extract_json([self.value], "dialog")
elif self.value is not None:
json["selected_options"] = Option.from_single_value(self.value)
else:
if isinstance(self.value, Option):
else:
json["value"] = self.value.value
elif self.value is not None:
json["value"] = self.value
elif self.value is not None:
json["selected_options"] = Option.from_single_value(self.value)
Comment on lines -190 to +196
Copy link
Author

Choose a reason for hiding this comment

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

Function AbstractDialogSelector.to_dict refactored with the following changes:

  • Hoist repeated code outside conditional statement (hoist-statement-from-if)

return json


Expand Down
5 changes: 1 addition & 4 deletions slack/web/classes/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ def state(self, state: Union[dict, str]) -> "DialogBuilder":
state: Extra state information that you need to pass from this dialog
back to your application on submission
"""
if isinstance(state, dict):
self._state = dumps(state)
else:
self._state = state
self._state = dumps(state) if isinstance(state, dict) else state
Copy link
Author

Choose a reason for hiding this comment

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

Function DialogBuilder.state refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

return self

def callback_id(self, callback_id: str) -> "DialogBuilder":
Expand Down
14 changes: 4 additions & 10 deletions slack/web/classes/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def __init__(self, event: dict):
self.callback_id = event["callback_id"]
self.event_type = event["type"]
self.submission = event["submission"]
if event["state"]:
self.state = json.loads(event["state"])
else:
self.state = {}
self.state = json.loads(event["state"]) if event["state"] else {}
Copy link
Author

Choose a reason for hiding this comment

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

Function DialogInteractiveEvent.__init__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)


def require_any(self, requirements: List[str]) -> dict:
"""
Expand All @@ -94,12 +91,9 @@ def require_any(self, requirements: List[str]) -> dict:
"""
if any(self.submission.get(requirement, "") for requirement in requirements):
return {}
else:
errors = []
for key in self.submission:
error_text = "At least one value is required"
errors.append({"name": key, "error": error_text})
return {"errors": errors}
error_text = "At least one value is required"
errors = [{"name": key, "error": error_text} for key in self.submission]
return {"errors": errors}
Comment on lines -97 to +96
Copy link
Author

Choose a reason for hiding this comment

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

Function DialogInteractiveEvent.require_any refactored with the following changes:

  • Hoist statements out of for/while loops (hoist-statement-from-loop)
  • Remove unnecessary else after guard condition (remove-unnecessary-else)
  • Convert for loop into list comprehension (list-comprehension)



class SlashCommandInteractiveEvent(InteractiveEvent):
Expand Down
36 changes: 13 additions & 23 deletions slack/web/classes/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ def __init__(self, *, url: str, text: str):
self.text = text

def __str__(self):
if self.text:
separator = "|"
else:
separator = ""
separator = "|" if self.text else ""
Copy link
Author

Choose a reason for hiding this comment

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

Function Link.__str__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

return f"<{self.url}{separator}{self.text}>"


Expand Down Expand Up @@ -57,14 +54,8 @@ def __init__(
fallback: text to display on clients that don't support date rendering
link: an optional URL to hyperlink to with this date
"""
if isinstance(date, datetime):
epoch = int(date.timestamp())
else:
epoch = date
if link is not None:
link = f"^{link}"
else:
link = ""
epoch = int(date.timestamp()) if isinstance(date, datetime) else date
link = f"^{link}" if link is not None else ""
Comment on lines -60 to +58
Copy link
Author

Choose a reason for hiding this comment

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

Function DateLink.__init__ refactored with the following changes:

  • Replace if statement with if expression (assign-if-exp)

super().__init__(url=f"{epoch}^{date_format}{link}", text=fallback)


Expand Down Expand Up @@ -272,18 +263,17 @@ def to_dict(self, option_type: str = "block") -> dict:
"ok_text": self.confirm if self.confirm != "Yes" else "Okay",
"dismiss_text": self.deny if self.deny != "No" else "Cancel",
}
self.validate_json()
json = {
"title": PlainTextObject.direct_from_string(self.title),
"confirm": PlainTextObject.direct_from_string(self.confirm),
"deny": PlainTextObject.direct_from_string(self.deny),
}
if isinstance(self.text, TextObject):
json["text"] = self.text.to_dict()
else:
self.validate_json()
json = {
"title": PlainTextObject.direct_from_string(self.title),
"confirm": PlainTextObject.direct_from_string(self.confirm),
"deny": PlainTextObject.direct_from_string(self.deny),
}
if isinstance(self.text, TextObject):
json["text"] = self.text.to_dict()
else:
json["text"] = MarkdownTextObject.direct_from_string(self.text)
return json
json["text"] = MarkdownTextObject.direct_from_string(self.text)
return json
Comment on lines +266 to +276
Copy link
Author

Choose a reason for hiding this comment

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

Function ConfirmObject.to_dict refactored with the following changes:

  • Remove unnecessary else after guard condition (remove-unnecessary-else)



class Option(JsonObject):
Expand Down
3 changes: 1 addition & 2 deletions slack/web/slack_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ def _next_cursor_is_present(data):
Returns:
A boolean value.
"""
present = (
return (
"response_metadata" in data
and "next_cursor" in data["response_metadata"]
and data["response_metadata"]["next_cursor"] != ""
)
return present
Comment on lines -184 to -189
Copy link
Author

Choose a reason for hiding this comment

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

Function SlackResponse._next_cursor_is_present refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

6 changes: 2 additions & 4 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@


def fake_req_args(headers=ANY, data=ANY, params=ANY, json=ANY):
req_args = {
return {
Copy link
Author

Choose a reason for hiding this comment

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

Function fake_req_args refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

"headers": headers,
"data": data,
"params": params,
"json": json,
"ssl": ANY,
"proxy": ANY,
}
return req_args


def fake_send_req_args(headers=ANY, data=ANY, params=ANY, json=ANY):
req_args = {
return {
Comment on lines -24 to +23
Copy link
Author

Choose a reason for hiding this comment

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

Function fake_send_req_args refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

"headers": headers,
"data": data,
"params": params,
Expand All @@ -30,7 +29,6 @@ def fake_send_req_args(headers=ANY, data=ANY, params=ANY, json=ANY):
"proxy": ANY,
"files": ANY,
}
return req_args


def mock_rtm_response():
Expand Down
5 changes: 2 additions & 3 deletions tests/rtm/test_rtm_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ def stop_on_open(**payload):

if rtm_client._connection_attempts == 1:
raise e.SlackApiError("Test Error", {"headers": {"Retry-After": 0.001}})
else:
self.assertEqual(rtm_client._connection_attempts, 2)
rtm_client.stop()
self.assertEqual(rtm_client._connection_attempts, 2)
rtm_client.stop()
Comment on lines -87 to +88
Copy link
Author

Choose a reason for hiding this comment

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

Function TestRTMClientFunctional.test_client_auto_reconnects_if_an_error_is_thrown.stop_on_open refactored with the following changes:

  • Remove unnecessary else after guard condition (remove-unnecessary-else)


client = slack.RTMClient(token="xoxa-1234", auto_reconnect=True)
client.start()
Expand Down
4 changes: 2 additions & 2 deletions tests/web/test_web_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_requests_can_be_paginated(self, mock_request):

users = []
for page in self.client.users_list(limit=2):
users = users + page["members"]
users += page["members"]
Copy link
Author

Choose a reason for hiding this comment

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

Function TestWebClient.test_requests_can_be_paginated refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

self.assertTrue(len(users) == 4)

def test_request_pagination_stops_when_next_cursor_is_missing(self, mock_request):
Expand All @@ -102,7 +102,7 @@ def test_request_pagination_stops_when_next_cursor_is_missing(self, mock_request

users = []
for page in self.client.users_list(limit=2):
users = users + page["members"]
users += page["members"]
Copy link
Author

Choose a reason for hiding this comment

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

Function TestWebClient.test_request_pagination_stops_when_next_cursor_is_missing refactored with the following changes:

  • Replace assignment with augmented assignment (aug-assign)

self.assertTrue(len(users) == 2)
mock_request.assert_called_once_with(
http_verb="GET",
Expand Down