-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery Starbot ⭐ refactored marks/python-slackclient #1
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return json | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return self | ||
|
|
||
| def callback_id(self, callback_id: str) -> "DialogBuilder": | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 {} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def require_any(self, requirements: List[str]) -> dict: | ||
| """ | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class SlashCommandInteractiveEvent(InteractiveEvent): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 "" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return f"<{self.url}{separator}{self.text}>" | ||
|
|
||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| super().__init__(url=f"{epoch}^{date_format}{link}", text=fallback) | ||
|
|
||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class Option(JsonObject): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,19 +9,18 @@ | |
|
|
||
|
|
||
| def fake_req_args(headers=ANY, data=ANY, params=ANY, json=ANY): | ||
| req_args = { | ||
| return { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| "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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| "headers": headers, | ||
| "data": data, | ||
| "params": params, | ||
|
|
@@ -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(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| client = slack.RTMClient(token="xoxa-1234", auto_reconnect=True) | ||
| client.start() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertTrue(len(users) == 4) | ||
|
|
||
| def test_request_pagination_stops_when_next_cursor_is_missing(self, mock_request): | ||
|
|
@@ -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"] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertTrue(len(users) == 2) | ||
| mock_request.assert_called_once_with( | ||
| http_verb="GET", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
BaseClient._get_user_agentrefactored with the following changes:inline-immediately-returned-variable)