Skip to content

Commit 8c4882d

Browse files
WilliamBergaminClaude
andauthored
chore: add docstring formatting + linting (#1959)
Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent 2643bcc commit 8c4882d

71 files changed

Lines changed: 1519 additions & 656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pyproject.toml‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,26 @@ universal = true
5959
line-length = 125
6060

6161
[tool.ruff.lint]
62-
select = ["E", "W", "F"]
62+
select = ["E", "W", "F", "D"]
63+
ignore = [
64+
# missing-docstring: do not add docstrings where none exist
65+
"D100",
66+
"D101",
67+
"D102",
68+
"D103",
69+
"D104",
70+
"D105",
71+
"D106",
72+
"D107",
73+
# undocumented-param: 51/54 cases are just **others/**kwargs boilerplate in Block Kit models
74+
"D417",
75+
]
76+
77+
[tool.ruff.lint.pydocstyle]
78+
convention = "google"
79+
80+
[tool.ruff.format]
81+
docstring-code-format = true
6382

6483
[tool.pytest.ini_options]
6584
testpaths = ["tests"]

‎slack/signature/verifier.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def now() -> float:
1212

1313
class SignatureVerifier:
1414
def __init__(self, signing_secret: str, clock: Clock = Clock()):
15-
"""Slack request signature verifier
15+
"""Slack request signature verifier.
1616
1717
Slack signs its requests using a secret that's unique to your app.
1818
With the help of signing secrets, your app can more confidently verify
@@ -27,7 +27,7 @@ def is_valid_request(
2727
body: Union[str, bytes],
2828
headers: Dict[str, str],
2929
) -> bool:
30-
"""Verifies if the given signature is valid"""
30+
"""Verifies if the given signature is valid."""
3131
if headers is None:
3232
return False
3333
normalized_headers = {k.lower(): v for k, v in headers.items()}
@@ -43,7 +43,7 @@ def is_valid(
4343
timestamp: str,
4444
signature: str,
4545
) -> bool:
46-
"""Verifies if the given signature is valid"""
46+
"""Verifies if the given signature is valid."""
4747
if timestamp is None or signature is None:
4848
return False
4949

@@ -56,7 +56,7 @@ def is_valid(
5656
return hmac.compare_digest(calculated_signature, signature)
5757

5858
def generate_signature(self, *, timestamp: str, body: Union[str, bytes]) -> Optional[str]:
59-
"""Generates a signature"""
59+
"""Generates a signature."""
6060
if timestamp is None:
6161
return None
6262
if body is None:

‎slack/web/async_base_client.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ async def api_call( # skipcq: PYL-R1710
8888
SlackRequestError: Json data can only be submitted as
8989
POST requests.
9090
"""
91-
9291
api_url = _get_url(self.base_url, api_method)
9392
headers = headers or {}
9493
headers.update(self.headers)
@@ -128,6 +127,7 @@ async def _send(self, http_verb: str, api_url: str, req_args: dict) -> AsyncSlac
128127
'channel': '#random'
129128
}
130129
}
130+
131131
Returns:
132132
The response parsed into a AsyncSlackResponse object.
133133
"""
@@ -152,6 +152,7 @@ async def _send(self, http_verb: str, api_url: str, req_args: dict) -> AsyncSlac
152152

153153
async def _request(self, *, http_verb, api_url, req_args) -> Dict[str, any]:
154154
"""Submit the HTTP request with the running session or a new session.
155+
155156
Returns:
156157
A dictionary of the response data.
157158
"""

‎slack/web/async_internal_utils.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _get_headers(
4646
request_specific_headers: Optional[dict],
4747
) -> Dict[str, str]:
4848
"""Constructs the headers need for a request.
49+
4950
Args:
5051
has_json (bool): Whether or not the request has json.
5152
has_files (bool): Whether or not the request has files.
@@ -163,6 +164,7 @@ async def _request_with_session(
163164
req_args: dict,
164165
) -> Dict[str, any]:
165166
"""Submit the HTTP request with the running session or a new session.
167+
166168
Returns:
167169
A dictionary of the response data.
168170
"""

‎slack/web/async_slack_response.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ class AsyncSlackResponse:
2424
import os
2525
import slack
2626
27-
client = slack.AsyncWebClient(token=os.environ['SLACK_API_TOKEN'])
27+
client = slack.AsyncWebClient(token=os.environ["SLACK_API_TOKEN"])
2828
29-
response1 = await client.auth_revoke(test='true')
30-
assert not response1['revoked']
29+
response1 = await client.auth_revoke(test="true")
30+
assert not response1["revoked"]
3131
3232
response2 = await client.auth_test()
33-
assert response2.get('ok', False)
33+
assert response2.get("ok", False)
3434
3535
users = []
3636
async for page in await client.users_list(limit=2):
37-
users = users + page['members']
37+
users = users + page["members"]
3838
```
3939
4040
Note:
@@ -100,6 +100,7 @@ def __getitem__(self, key):
100100

101101
def __aiter__(self):
102102
"""Enables the ability to iterate over the response.
103+
103104
It's required async-for the iterator protocol.
104105
105106
Note:

‎slack/web/base_client.py‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ def api_call( # skipcq: PYL-R1710
111111
SlackRequestError: Json data can only be submitted as
112112
POST requests.
113113
"""
114-
115114
api_url = _get_url(self.base_url, api_method)
116115
headers = headers or {}
117116
headers.update(self.headers)
@@ -165,6 +164,7 @@ async def _send(self, http_verb: str, api_url: str, req_args: dict) -> SlackResp
165164
'channel': '#random'
166165
}
167166
}
167+
168168
Returns:
169169
The response parsed into a SlackResponse object.
170170
"""
@@ -190,6 +190,7 @@ async def _send(self, http_verb: str, api_url: str, req_args: dict) -> SlackResp
190190

191191
async def _request(self, *, http_verb, api_url, req_args) -> Dict[str, any]:
192192
"""Submit the HTTP request with the running session or a new session.
193+
193194
Returns:
194195
A dictionary of the response data.
195196
"""
@@ -239,7 +240,7 @@ def _sync_send(self, api_url, req_args) -> SlackResponse:
239240
)
240241

241242
def _request_for_pagination(self, api_url, req_args) -> Dict[str, any]:
242-
"""This method is supposed to be used only for SlackResponse pagination
243+
"""This method is supposed to be used only for SlackResponse pagination.
243244
244245
You can paginate using Python's for iterator as below:
245246
@@ -463,9 +464,9 @@ def _build_urllib_request_headers(
463464

464465
@staticmethod
465466
def validate_slack_signature(*, signing_secret: str, data: str, timestamp: str, signature: str) -> bool:
466-
"""
467-
Slack creates a unique string for your app and shares it with you. Verify
468-
requests from Slack with confidence by verifying signatures using your
467+
"""Slack creates a unique string for your app and shares it with you.
468+
469+
Verify requests from Slack with confidence by verifying signatures using your
469470
signing secret.
470471
471472
On each HTTP request that Slack sends, we add an X-Slack-Signature HTTP

‎slack/web/classes/interactions.py‎

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class IDNamePair(NamedTuple):
8-
"""Simple type used to help with unpacking event data"""
8+
"""Simple type used to help with unpacking event data."""
99

1010
id: str
1111
name: str
@@ -33,8 +33,7 @@ class MessageInteractiveEvent(InteractiveEvent):
3333
message: dict
3434

3535
def __init__(self, event: dict):
36-
"""
37-
Convenience class to parse an interactive message payload from the events API
36+
"""Convenience class to parse an interactive message payload from the events API.
3837
3938
Args:
4039
event: the raw event dictionary
@@ -64,8 +63,7 @@ class DialogInteractiveEvent(InteractiveEvent):
6463
state: dict
6564

6665
def __init__(self, event: dict):
67-
"""
68-
Convenience class to parse a dialog interaction payload from the events API
66+
"""Convenience class to parse a dialog interaction payload from the events API.
6967
7068
Args:
7169
event: the raw event dictionary
@@ -83,9 +81,7 @@ def __init__(self, event: dict):
8381
self.state = {}
8482

8583
def require_any(self, requirements: List[str]) -> dict:
86-
"""
87-
Convenience method to construct the 'errors' response to send directly back to
88-
the invoking HTTP request
84+
"""Convenience method to construct the 'errors' response to send directly back to the invoking HTTP request.
8985
9086
Args:
9187
requirements: List of required dialog components, by name
@@ -106,8 +102,7 @@ class SlashCommandInteractiveEvent(InteractiveEvent):
106102
text: str
107103

108104
def __init__(self, event: dict):
109-
"""
110-
Convenience class to parse a slash command payload from the events API
105+
"""Convenience class to parse a slash command payload from the events API.
111106
112107
Args:
113108
event: the raw event dictionary
@@ -122,8 +117,7 @@ def __init__(self, event: dict):
122117

123118
@staticmethod
124119
def create_reply(message, ephemeral=False) -> dict:
125-
"""
126-
Create a reply suitable to send directly back to the invoking HTTP request
120+
"""Create a reply suitable to send directly back to the invoking HTTP request.
127121
128122
Args:
129123
message: Text to send

‎slack/web/deprecation.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313

1414
def show_2020_01_deprecation(method_name: str):
15-
"""Prints a warning if the given method is deprecated"""
16-
15+
"""Prints a warning if the given method is deprecated."""
1716
skip_deprecation = os.environ.get("SLACKCLIENT_SKIP_DEPRECATION") # for unit tests etc.
1817
if skip_deprecation:
1918
return

‎slack/web/internal_utils.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def _update_call_participants(kwargs, users: Union[str, List[Dict[str, str]]]) -
3838

3939

4040
def _next_cursor_is_present(data) -> bool:
41-
"""Determine if the response contains 'next_cursor'
42-
and 'next_cursor' is not empty.
41+
"""Determine if the response contains 'next_cursor' and 'next_cursor' is not empty.
4342
4443
Returns:
4544
A boolean value.

‎slack_sdk/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""
2-
* The SDK website: https://docs.slack.dev/tools/python-slack-sdk
1+
"""* The SDK website: https://docs.slack.dev/tools/python-slack-sdk.
2+
33
* PyPI package: https://pypi.org/project/slack-sdk/
44
55
Here is the list of key modules in this SDK:

0 commit comments

Comments
 (0)