Skip to content

Commit 48a9693

Browse files
authored
refactor: Sourcery AI refactor (#898)
* refactor: sourcery AI refactor * refactor: sourcery AI refactor * refactor: sourcery AI refactor
1 parent d5745bb commit 48a9693

File tree

16 files changed

+59
-56
lines changed

16 files changed

+59
-56
lines changed

interactions/api/gateway/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ async def wait_until_ready(self) -> None:
264264
"""Waits for the client to become ready according to the Gateway."""
265265
await self.ready.wait()
266266

267-
def _dispatch_event(self, event: str, data: dict) -> None: # sourcery no-metrics
267+
def _dispatch_event(self, event: str, data: dict) -> None:
268268
"""
269269
Dispatches an event from the Gateway.
270270
@@ -273,11 +273,12 @@ def _dispatch_event(self, event: str, data: dict) -> None: # sourcery no-metric
273273
:param data: The data for the event.
274274
:type data: dict
275275
"""
276+
# sourcery no-metrics
276277
path: str = "interactions"
277278
path += ".models" if event == "INTERACTION_CREATE" else ".api.models"
278279
if event == "INTERACTION_CREATE":
279280
if data.get("type"):
280-
# sourcery skip: extract-method
281+
# sourcery skip: dict-assign-update-to-union, extract-method, low-code-quality
281282
_context = self.__contextualize(data)
282283
_name: str = ""
283284
__args: list = [_context]

interactions/api/gateway/heartbeat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import contextlib
12
from asyncio import AbstractEventLoop, Event
23
from sys import version_info
34

@@ -15,8 +16,6 @@ def __init__(self, loop: AbstractEventLoop) -> None:
1516
:param loop: The event loop to base the asynchronous manager.
1617
:type loop: AbstractEventLoop
1718
"""
18-
try:
19+
with contextlib.suppress(TypeError):
1920
self.event = Event(loop=loop) if version_info < (3, 10) else Event()
20-
except TypeError:
21-
pass
2221
self.delay = 0.0

interactions/api/http/invite.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ async def get_invite(
3333
"""
3434
params_set = {
3535
"with_counts=true" if with_counts else None,
36-
"with_expiration=false" if not with_expiration else None,
36+
None if with_expiration else "with_expiration=false",
3737
f"guild_scheduled_event_id={guild_scheduled_event_id}"
3838
if guild_scheduled_event_id
3939
else None,
4040
}
41+
4142
final = "&".join([item for item in params_set if item is not None])
4243

4344
return await self._req.request(
44-
Route("GET", f"/invites/{invite_code}{'?' + final if final is not None else ''}")
45+
Route("GET", f"/invites/{invite_code}{f'?{final}' if final is not None else ''}")
4546
)
4647

4748
async def delete_invite(self, invite_code: str, reason: Optional[str] = None) -> dict:

interactions/api/http/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async def edit_message(
175175
file._fp,
176176
)
177177
part.set_content_disposition(
178-
"form-data", name="files[" + str(id) + "]", filename=file._filename
178+
"form-data", name=f"files[{str(id)}]", filename=file._filename
179179
)
180180

181181
return await self._req.request(

interactions/api/http/reaction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,10 @@ async def get_reactions_of_emoji(
137137
return await self._req.request(
138138
Route(
139139
"GET",
140-
"/channels/{channel_id}/messages/{message_id}/reactions/{emoji}"
141-
+ f"{'?' + final if final is not None else ''}",
140+
(
141+
"/channels/{channel_id}/messages/{message_id}/reactions/{emoji}"
142+
+ f"{f'?{final}' if final is not None else ''}"
143+
),
142144
channel_id=channel_id,
143145
message_id=message_id,
144146
emoji=emoji,

interactions/api/http/request.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
9898
:return: The contents of the request if any.
9999
:rtype: Optional[Any]
100100
"""
101+
# sourcery skip: low-code-quality
101102

102103
kwargs["headers"] = {**self._headers, **kwargs.get("headers", {})}
103104

104105
if kwargs.get("json"):
105106
kwargs["headers"]["Content-Type"] = "application/json"
106107

107-
reason = kwargs.pop("reason", None)
108-
if reason:
108+
if reason := kwargs.pop("reason", None):
109109
kwargs["headers"]["X-Audit-Log-Reason"] = quote(reason, safe="/ ")
110110

111111
# Huge credit and thanks to LordOfPolls for the lock/retry logic.
@@ -185,21 +185,21 @@ async def request(self, route: Route, **kwargs) -> Optional[Any]:
185185
severity=50,
186186
)
187187
if response.status == 429:
188-
if not is_global:
189-
log.warning(
190-
f"The HTTP client has encountered a per-route ratelimit. Locking down future requests for {reset_after} seconds."
191-
)
192-
_limiter.reset_after = reset_after
193-
await asyncio.sleep(_limiter.reset_after)
194-
continue
195-
else:
188+
if is_global:
196189
log.warning(
197190
f"The HTTP client has encountered a global ratelimit. Locking down future requests for {reset_after} seconds."
198191
)
199192
self._global_lock.reset_after = reset_after
200193
self._loop.call_later(
201194
self._global_lock.reset_after, self._global_lock.lock.release
202195
)
196+
else:
197+
log.warning(
198+
f"The HTTP client has encountered a per-route ratelimit. Locking down future requests for {reset_after} seconds."
199+
)
200+
_limiter.reset_after = reset_after
201+
await asyncio.sleep(_limiter.reset_after)
202+
continue
203203
if remaining is not None and int(remaining) == 0:
204204
log.warning(
205205
f"The HTTP client has exhausted a per-route ratelimit. Locking route for {reset_after} seconds."

interactions/api/http/scheduledEvent.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ async def create_scheduled_event(self, guild_id: Snowflake, payload: dict) -> di
3838
data = {k: v for k, v in payload.items() if k in valid_keys}
3939

4040
return await self._req.request(
41-
Route("POST", "/guilds/{guild_id}/scheduled-events", guild_id=int(guild_id)),
42-
json=data,
41+
Route("POST", "/guilds/{guild_id}/scheduled-events", guild_id=guild_id), json=data
4342
)
4443

4544
async def get_scheduled_event(

interactions/api/models/attrs_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class DictSerializerMixin:
2323
"""Should the kwargs be deepcopied or not?"""
2424

2525
def __init__(self, kwargs_dict: dict = None, /, **other_kwargs):
26+
# sourcery skip: low-code-quality
2627
kwargs = kwargs_dict or other_kwargs
2728
client = kwargs.pop("_client", None)
2829

interactions/api/models/channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async def send(
199199
List["SelectMenu"],
200200
]
201201
] = MISSING,
202-
) -> "Message":
202+
) -> "Message": # noqa # sourcery skip: dict-assign-update-to-union
203203
"""
204204
Sends a message in the channel.
205205
@@ -757,7 +757,7 @@ async def purge(
757757
before: Optional[int] = MISSING,
758758
reason: Optional[str] = None,
759759
bulk: Optional[bool] = True,
760-
) -> List["Message"]:
760+
) -> List["Message"]: # noqa # sourcery skip: low-code-quality
761761
"""
762762
Purges a given amount of messages from a channel. You can specify a check function to exclude specific messages.
763763

interactions/api/models/guild.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ async def modify_channel(
891891
auto_archive_duration: Optional[int] = MISSING,
892892
locked: Optional[bool] = MISSING,
893893
reason: Optional[str] = None,
894-
) -> Channel:
894+
) -> Channel: # sourcery skip: low-code-quality
895895
"""
896896
Edits a channel of the guild.
897897
@@ -1124,7 +1124,7 @@ async def modify(
11241124
description: Optional[str] = MISSING,
11251125
premium_progress_bar_enabled: Optional[bool] = MISSING,
11261126
reason: Optional[str] = None,
1127-
) -> "Guild":
1127+
) -> "Guild": # sourcery skip: low-code-quality
11281128
"""
11291129
Modifies the current guild.
11301130
@@ -2181,7 +2181,7 @@ async def modify_auto_moderation_rule(
21812181
exempt_roles: Optional[List[int]] = MISSING,
21822182
exempt_channels: Optional[List[int]] = MISSING,
21832183
reason: Optional[str] = None,
2184-
) -> "AutoModerationRule":
2184+
) -> "AutoModerationRule": # noqa # sourcery skip: compare-via-equals
21852185
"""
21862186
Edits an AutoMod rule
21872187

0 commit comments

Comments
 (0)