Skip to content

Commit 8d80259

Browse files
committed
Reformat shard.py
1 parent 311eac9 commit 8d80259

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

discord/shard.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060
log: logging.Logger = logging.getLogger(__name__)
6161

62+
6263
class EventType:
6364
close = 0
6465
reconnect = 1
@@ -67,6 +68,7 @@ class EventType:
6768
terminate = 4
6869
clean_close = 5
6970

71+
7072
class EventItem:
7173
__slots__ = ('type', 'shard', 'error')
7274

@@ -88,6 +90,7 @@ def __eq__(self: EI, other: EI) -> bool:
8890
def __hash__(self) -> int:
8991
return hash(self.type)
9092

93+
9194
class Shard:
9295
def __init__(self, ws: DiscordWebSocket, client: AutoShardedClient, queue_put: Callable[[EventItem], None]) -> None:
9396
self.ws: DiscordWebSocket = ws
@@ -111,7 +114,7 @@ def __init__(self, ws: DiscordWebSocket, client: AutoShardedClient, queue_put: C
111114
@property
112115
def id(self) -> int:
113116
# DiscordWebSocket.shard_id is set in the from_client classmethod
114-
return self.ws.shard_id # type: ignore
117+
return self.ws.shard_id # type: ignore
115118

116119
def launch(self) -> None:
117120
self._task = self.loop.create_task(self.worker())
@@ -180,8 +183,13 @@ async def reidentify(self, exc: ReconnectWebSocket) -> None:
180183
self._dispatch('shard_disconnect', self.id)
181184
log.info('Got a request to %s the websocket at Shard ID %s.', exc.op, self.id)
182185
try:
183-
coro = DiscordWebSocket.from_client(self._client, resume=exc.resume, shard_id=self.id,
184-
session=self.ws.session_id, sequence=self.ws.sequence)
186+
coro = DiscordWebSocket.from_client(
187+
self._client,
188+
resume=exc.resume,
189+
shard_id=self.id,
190+
session=self.ws.session_id,
191+
sequence=self.ws.sequence,
192+
)
185193
self.ws = await asyncio.wait_for(coro, timeout=60.0)
186194
except self._handled_exceptions as e:
187195
await self._handle_disconnect(e)
@@ -206,6 +214,7 @@ async def reconnect(self) -> None:
206214
else:
207215
self.launch()
208216

217+
209218
class ShardInfo:
210219
"""A class that gives information and control over a specific shard.
211220
@@ -280,6 +289,7 @@ def is_ws_ratelimited(self) -> bool:
280289
"""
281290
return self._parent.ws.is_ratelimited()
282291

292+
283293
class AutoShardedClient(Client):
284294
"""A client similar to :class:`Client` except it handles the complications
285295
of sharding for the user into a more manageable and transparent single
@@ -306,6 +316,7 @@ class AutoShardedClient(Client):
306316
shard_ids: Optional[List[:class:`int`]]
307317
An optional list of shard_ids to launch the shards with.
308318
"""
319+
309320
if TYPE_CHECKING:
310321
_connection: AutoShardedConnectionState
311322

@@ -330,13 +341,18 @@ def __init__(self, *args: Any, loop: Optional[asyncio.AbstractEventLoop] = None,
330341
def _get_websocket(self, guild_id: Optional[int] = None, *, shard_id: Optional[int] = None) -> DiscordWebSocket:
331342
if shard_id is None:
332343
# guild_id won't be None if shard_id is None and shard_count won't be None here
333-
shard_id = (guild_id >> 22) % self.shard_count # type: ignore
344+
shard_id = (guild_id >> 22) % self.shard_count # type: ignore
334345
return self.__shards[shard_id].ws
335346

336347
def _get_state(self, **options: Any) -> AutoShardedConnectionState:
337-
return AutoShardedConnectionState(dispatch=self.dispatch,
338-
handlers=self._handlers,
339-
hooks=self._hooks, http=self.http, loop=self.loop, **options)
348+
return AutoShardedConnectionState(
349+
dispatch=self.dispatch,
350+
handlers=self._handlers,
351+
hooks=self._hooks,
352+
http=self.http,
353+
loop=self.loop,
354+
**options,
355+
)
340356

341357
@property
342358
def latency(self) -> float:
@@ -370,7 +386,7 @@ def get_shard(self, shard_id: int) -> Optional[ShardInfo]:
370386
@property
371387
def shards(self) -> Dict[int, ShardInfo]:
372388
"""Mapping[int, :class:`ShardInfo`]: Returns a mapping of shard IDs to their respective info object."""
373-
return { shard_id: ShardInfo(parent, self.shard_count) for shard_id, parent in self.__shards.items() }
389+
return {shard_id: ShardInfo(parent, self.shard_count) for shard_id, parent in self.__shards.items()}
374390

375391
async def launch_shard(self, gateway: str, shard_id: int, *, initial: bool = False) -> None:
376392
try:
@@ -449,7 +465,13 @@ async def close(self) -> None:
449465
await self.http.close()
450466
self.__queue.put_nowait(EventItem(EventType.clean_close, None, None))
451467

452-
async def change_presence(self, *, activity: Optional[BaseActivity] = None, status: Optional[Status] = None, shard_id: int = None) -> None:
468+
async def change_presence(
469+
self,
470+
*,
471+
activity: Optional[BaseActivity] = None,
472+
status: Optional[Status] = None,
473+
shard_id: int = None,
474+
) -> None:
453475
"""|coro|
454476
455477
Changes the client's presence.
@@ -507,7 +529,7 @@ async def change_presence(self, *, activity: Optional[BaseActivity] = None, stat
507529
continue
508530

509531
# Member.activities is typehinted as Tuple[ActivityType, ...], we may be setting it as Tuple[BaseActivity, ...]
510-
me.activities = activities # type: ignore
532+
me.activities = activities # type: ignore
511533
me.status = status_enum
512534

513535
def is_ws_ratelimited(self) -> bool:

0 commit comments

Comments
 (0)