Browse Source

Handle type-errors in upcoming pyright release

pull/7494/head
Josh 3 years ago
committed by GitHub
parent
commit
a315786869
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      discord/embeds.py
  2. 4
      discord/ext/commands/flags.py
  3. 11
      discord/player.py
  4. 2
      discord/shard.py
  5. 2
      discord/voice_client.py

4
discord/embeds.py

@ -185,7 +185,7 @@ class Embed:
type: EmbedType = 'rich', type: EmbedType = 'rich',
url: MaybeEmpty[Any] = EmptyEmbed, url: MaybeEmpty[Any] = EmptyEmbed,
description: MaybeEmpty[Any] = EmptyEmbed, description: MaybeEmpty[Any] = EmptyEmbed,
timestamp: datetime.datetime = None, timestamp: MaybeEmpty[datetime.datetime] = EmptyEmbed,
): ):
self.colour = colour if colour is not EmptyEmbed else color self.colour = colour if colour is not EmptyEmbed else color
@ -203,7 +203,7 @@ class Embed:
if self.url is not EmptyEmbed: if self.url is not EmptyEmbed:
self.url = str(self.url) self.url = str(self.url)
if timestamp: if timestamp is not EmptyEmbed:
self.timestamp = timestamp self.timestamp = timestamp
@classmethod @classmethod

4
discord/ext/commands/flags.py

@ -416,9 +416,9 @@ async def convert_flag(ctx, argument: str, flag: Flag, annotation: Any = None) -
# typing.List[x] # typing.List[x]
annotation = annotation.__args__[0] annotation = annotation.__args__[0]
return await convert_flag(ctx, argument, flag, annotation) return await convert_flag(ctx, argument, flag, annotation)
elif origin is Union and annotation.__args__[-1] is type(None): elif origin is Union and type(None) in annotation.__args__:
# typing.Optional[x] # typing.Optional[x]
annotation = Union[annotation.__args__[:-1]] annotation = Union[tuple(arg for arg in annotation.__args__ if arg is not type(None))] # type: ignore
return await run_converters(ctx, annotation, argument, param) return await run_converters(ctx, annotation, argument, param)
elif origin is dict: elif origin is dict:
# typing.Dict[K, V] -> typing.Tuple[K, V] # typing.Dict[K, V] -> typing.Tuple[K, V]

11
discord/player.py

@ -38,6 +38,7 @@ import io
from typing import Any, Callable, Generic, IO, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union from typing import Any, Callable, Generic, IO, Optional, TYPE_CHECKING, Tuple, Type, TypeVar, Union
from .enums import SpeakingState
from .errors import ClientException from .errors import ClientException
from .opus import Encoder as OpusEncoder from .opus import Encoder as OpusEncoder
from .oggparse import OggStream from .oggparse import OggStream
@ -656,7 +657,7 @@ class AudioPlayer(threading.Thread):
# getattr lookup speed ups # getattr lookup speed ups
play_audio = self.client.send_audio_packet play_audio = self.client.send_audio_packet
self._speak(True) self._speak(SpeakingState.voice)
while not self._end.is_set(): while not self._end.is_set():
# are we paused? # are we paused?
@ -714,19 +715,19 @@ class AudioPlayer(threading.Thread):
def stop(self) -> None: def stop(self) -> None:
self._end.set() self._end.set()
self._resumed.set() self._resumed.set()
self._speak(False) self._speak(SpeakingState.none)
def pause(self, *, update_speaking: bool = True) -> None: def pause(self, *, update_speaking: bool = True) -> None:
self._resumed.clear() self._resumed.clear()
if update_speaking: if update_speaking:
self._speak(False) self._speak(SpeakingState.none)
def resume(self, *, update_speaking: bool = True) -> None: def resume(self, *, update_speaking: bool = True) -> None:
self.loops = 0 self.loops = 0
self._start = time.perf_counter() self._start = time.perf_counter()
self._resumed.set() self._resumed.set()
if update_speaking: if update_speaking:
self._speak(True) self._speak(SpeakingState.voice)
def is_playing(self) -> bool: def is_playing(self) -> bool:
return self._resumed.is_set() and not self._end.is_set() return self._resumed.is_set() and not self._end.is_set()
@ -740,7 +741,7 @@ class AudioPlayer(threading.Thread):
self.source = source self.source = source
self.resume(update_speaking=False) self.resume(update_speaking=False)
def _speak(self, speaking: bool) -> None: def _speak(self, speaking: SpeakingState) -> None:
try: try:
asyncio.run_coroutine_threadsafe(self.client.ws.speak(speaking), self.client.loop) asyncio.run_coroutine_threadsafe(self.client.ws.speak(speaking), self.client.loop)
except Exception as e: except Exception as e:

2
discord/shard.py

@ -481,7 +481,7 @@ class AutoShardedClient(Client):
*, *,
activity: Optional[BaseActivity] = None, activity: Optional[BaseActivity] = None,
status: Optional[Status] = None, status: Optional[Status] = None,
shard_id: int = None, shard_id: Optional[int] = None,
) -> None: ) -> None:
"""|coro| """|coro|

2
discord/voice_client.py

@ -563,7 +563,7 @@ class VoiceClient(VoiceProtocol):
return header + box.encrypt(bytes(data), bytes(nonce)).ciphertext + nonce[:4] return header + box.encrypt(bytes(data), bytes(nonce)).ciphertext + nonce[:4]
def play(self, source: AudioSource, *, after: Callable[[Optional[Exception]], Any] = None) -> None: def play(self, source: AudioSource, *, after: Optional[Callable[[Optional[Exception]], Any]] = None) -> None:
"""Plays an :class:`AudioSource`. """Plays an :class:`AudioSource`.
The finalizer, ``after`` is called after the source has been exhausted The finalizer, ``after`` is called after the source has been exhausted

Loading…
Cancel
Save