Fix code style issues with Black

This commit is contained in:
Lint Action
2021-09-05 21:34:20 +00:00
parent a23dae8604
commit 7513c2138f
108 changed files with 5369 additions and 4858 deletions

View File

@@ -50,11 +50,11 @@ if TYPE_CHECKING:
from .activity import BaseActivity
from .enums import Status
EI = TypeVar('EI', bound='EventItem')
EI = TypeVar("EI", bound="EventItem")
__all__ = (
'AutoShardedClient',
'ShardInfo',
"AutoShardedClient",
"ShardInfo",
)
_log = logging.getLogger(__name__)
@@ -70,11 +70,11 @@ class EventType:
class EventItem:
__slots__ = ('type', 'shard', 'error')
__slots__ = ("type", "shard", "error")
def __init__(self, etype: int, shard: Optional['Shard'], error: Optional[Exception]) -> None:
def __init__(self, etype: int, shard: Optional["Shard"], error: Optional[Exception]) -> None:
self.type: int = etype
self.shard: Optional['Shard'] = shard
self.shard: Optional["Shard"] = shard
self.error: Optional[Exception] = error
def __lt__(self: EI, other: EI) -> bool:
@@ -129,11 +129,11 @@ class Shard:
async def disconnect(self) -> None:
await self.close()
self._dispatch('shard_disconnect', self.id)
self._dispatch("shard_disconnect", self.id)
async def _handle_disconnect(self, e: Exception) -> None:
self._dispatch('disconnect')
self._dispatch('shard_disconnect', self.id)
self._dispatch("disconnect")
self._dispatch("shard_disconnect", self.id)
if not self._reconnect:
self._queue_put(EventItem(EventType.close, self, e))
return
@@ -156,7 +156,7 @@ class Shard:
return
retry = self._backoff.delay()
_log.error('Attempting a reconnect for shard ID %s in %.2fs', self.id, retry, exc_info=e)
_log.error("Attempting a reconnect for shard ID %s in %.2fs", self.id, retry, exc_info=e)
await asyncio.sleep(retry)
self._queue_put(EventItem(EventType.reconnect, self, e))
@@ -179,9 +179,9 @@ class Shard:
async def reidentify(self, exc: ReconnectWebSocket) -> None:
self._cancel_task()
self._dispatch('disconnect')
self._dispatch('shard_disconnect', self.id)
_log.info('Got a request to %s the websocket at Shard ID %s.', exc.op, self.id)
self._dispatch("disconnect")
self._dispatch("shard_disconnect", self.id)
_log.info("Got a request to %s the websocket at Shard ID %s.", exc.op, self.id)
try:
coro = DiscordWebSocket.from_client(
self._client,
@@ -231,7 +231,7 @@ class ShardInfo:
The shard count for this cluster. If this is ``None`` then the bot has not started yet.
"""
__slots__ = ('_parent', 'id', 'shard_count')
__slots__ = ("_parent", "id", "shard_count")
def __init__(self, parent: Shard, shard_count: Optional[int]) -> None:
self._parent: Shard = parent
@@ -321,15 +321,15 @@ class AutoShardedClient(Client):
_connection: AutoShardedConnectionState
def __init__(self, *args: Any, loop: Optional[asyncio.AbstractEventLoop] = None, **kwargs: Any) -> None:
kwargs.pop('shard_id', None)
self.shard_ids: Optional[List[int]] = kwargs.pop('shard_ids', None)
kwargs.pop("shard_id", None)
self.shard_ids: Optional[List[int]] = kwargs.pop("shard_ids", None)
super().__init__(*args, loop=loop, **kwargs)
if self.shard_ids is not None:
if self.shard_count is None:
raise ClientException('When passing manual shard_ids, you must provide a shard_count.')
raise ClientException("When passing manual shard_ids, you must provide a shard_count.")
elif not isinstance(self.shard_ids, (list, tuple)):
raise ClientException('shard_ids parameter must be a list or a tuple.')
raise ClientException("shard_ids parameter must be a list or a tuple.")
# instead of a single websocket, we have multiple
# the key is the shard_id
@@ -363,7 +363,7 @@ class AutoShardedClient(Client):
:attr:`latencies` property. Returns ``nan`` if there are no shards ready.
"""
if not self.__shards:
return float('nan')
return float("nan")
return sum(latency for _, latency in self.latencies) / len(self.__shards)
@property
@@ -393,7 +393,7 @@ class AutoShardedClient(Client):
coro = DiscordWebSocket.from_client(self, initial=initial, gateway=gateway, shard_id=shard_id)
ws = await asyncio.wait_for(coro, timeout=180.0)
except Exception:
_log.exception('Failed to connect for shard_id: %s. Retrying...', shard_id)
_log.exception("Failed to connect for shard_id: %s. Retrying...", shard_id)
await asyncio.sleep(5.0)
return await self.launch_shard(gateway, shard_id)
@@ -503,10 +503,10 @@ class AutoShardedClient(Client):
"""
if status is None:
status_value = 'online'
status_value = "online"
status_enum = Status.online
elif status is Status.offline:
status_value = 'invisible'
status_value = "invisible"
status_enum = Status.offline
else:
status_enum = status