mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-05 19:37:25 +00:00
Change loop sentinel to provide a more descriptive error message
This way people don't think it's a bug. I imagine some people won't read it, but at least when you point it out they might get it.
This commit is contained in:
parent
aa18e573c3
commit
9b77331603
@ -99,6 +99,21 @@ Coro = TypeVar('Coro', bound=Callable[..., Coroutine[Any, Any, Any]])
|
|||||||
_log = logging.getLogger(__name__)
|
_log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class _LoopSentinel:
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
|
def __getattr__(self, attr: str) -> None:
|
||||||
|
msg = (
|
||||||
|
'loop attribute cannot be accessed in non-async contexts. ',
|
||||||
|
'Consider using either an asynchronous main function and passing it to asyncio.run or ',
|
||||||
|
'using asynchronous initialisation hooks such as Client.setup_hook',
|
||||||
|
)
|
||||||
|
raise AttributeError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
_loop: Any = _LoopSentinel()
|
||||||
|
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
r"""Represents a client connection that connects to Discord.
|
r"""Represents a client connection that connects to Discord.
|
||||||
This class is used to interact with the Discord WebSocket and API.
|
This class is used to interact with the Discord WebSocket and API.
|
||||||
@ -184,7 +199,7 @@ class Client:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, **options: Any) -> None:
|
def __init__(self, **options: Any) -> None:
|
||||||
self.loop: asyncio.AbstractEventLoop = MISSING
|
self.loop: asyncio.AbstractEventLoop = _loop
|
||||||
# self.ws is set in the connect method
|
# self.ws is set in the connect method
|
||||||
self.ws: DiscordWebSocket = None # type: ignore
|
self.ws: DiscordWebSocket = None # type: ignore
|
||||||
self._listeners: Dict[str, List[Tuple[asyncio.Future, Callable[..., bool]]]] = {}
|
self._listeners: Dict[str, List[Tuple[asyncio.Future, Callable[..., bool]]]] = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user