Skip to content

Commit

Permalink
fix: Remove deprecated get_event_loop() in favor of new_event_loop()
Browse files Browse the repository at this point in the history
  • Loading branch information
Revnoplex committed Oct 19, 2024
1 parent 72ba1b1 commit 4800b75
Show file tree
Hide file tree
Showing 33 changed files with 58 additions and 59 deletions.
4 changes: 2 additions & 2 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Client:
loop: Optional[:class:`asyncio.AbstractEventLoop`]
The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations.
Defaults to ``None``, in which case the default event loop is used via
:func:`asyncio.get_event_loop()`.
:func:`asyncio.new_event_loop()`.
connector: Optional[:class:`aiohttp.BaseConnector`]
The connector to use for connection pooling.
proxy: Optional[:class:`str`]
Expand Down Expand Up @@ -227,7 +227,7 @@ def __init__(
# self.ws is set in the connect method
self.ws: DiscordWebSocket = None # type: ignore
self.loop: asyncio.AbstractEventLoop = (
asyncio.get_event_loop() if loop is None else loop
asyncio.new_event_loop() if loop is None else loop
)
self._listeners: dict[str, list[tuple[asyncio.Future, Callable[..., bool]]]] = (
{}
Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/cooldowns.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class _Semaphore:

def __init__(self, number: int) -> None:
self.value: int = number
self.loop: asyncio.AbstractEventLoop = asyncio.get_event_loop()
self.loop: asyncio.AbstractEventLoop = asyncio.new_event_loop()
self._waiters: Deque[asyncio.Future] = deque()

def __repr__(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions discord/ext/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def start(self, *args: Any, **kwargs: Any) -> asyncio.Task[None]:
args = (self._injected, *args)

if self.loop is MISSING:
self.loop = asyncio.get_event_loop()
self.loop = asyncio.new_event_loop()

self._task = self.loop.create_task(self._loop(*args, **kwargs))
return self._task
Expand Down Expand Up @@ -771,7 +771,7 @@ def loop(
one used in :meth:`discord.Client.connect`.
loop: :class:`asyncio.AbstractEventLoop`
The loop to use to register the task, if not given
defaults to :func:`asyncio.get_event_loop`.
defaults to :func:`asyncio.new_event_loop`.
Raises
------
Expand Down
2 changes: 1 addition & 1 deletion discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __init__(
unsync_clock: bool = True,
) -> None:
self.loop: asyncio.AbstractEventLoop = (
asyncio.get_event_loop() if loop is None else loop
asyncio.new_event_loop() if loop is None else loop
)
self.connector = connector
self.__session: aiohttp.ClientSession = MISSING # filled in static_login
Expand Down
2 changes: 1 addition & 1 deletion discord/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ async def probe(
)

codec = bitrate = None
loop = asyncio.get_event_loop()
loop = asyncio.get_running_loop()
try:
codec, bitrate = await loop.run_in_executor(None, lambda: probefunc(source, executable)) # type: ignore
except Exception:
Expand Down
5 changes: 2 additions & 3 deletions discord/ui/modal.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,11 @@ def __init__(
self._title = title
self._children: list[InputText] = list(children)
self._weights = _ModalWeights(self._children)
loop = asyncio.get_running_loop()
self._stopped: asyncio.Future[bool] = loop.create_future()
self.loop = asyncio.get_running_loop()
self._stopped: asyncio.Future[bool] = self.loop.create_future()
self.__cancel_callback: Callable[[Modal], None] | None = None
self.__timeout_expiry: float | None = None
self.__timeout_task: asyncio.Task[None] | None = None
self.loop = asyncio.get_event_loop()

def _start_listening_from_store(self, store: ModalStore) -> None:
self.__cancel_callback = partial(store.remove_modal)
Expand Down
2 changes: 1 addition & 1 deletion docs/build/locales/api/clients.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3706,7 +3706,7 @@ msgstr ""

#: ../../../discord/client.py:docstring of discord.client.Client:13
#: 6c88dd4b014e4fd68019bf91e0e79449
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr ""

#: ../../../discord/client.py:docstring of discord.client.Client:17
Expand Down
2 changes: 1 addition & 1 deletion docs/build/locales/ext/tasks/index.pot
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ msgstr ""

#: ../../../discord/ext/tasks/__init__.py:docstring of discord.ext.tasks.loop:36
#: 7e644a647eaa4981aad624c207683f5a
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr ""

#: ../../../discord/ext/tasks/__init__.py:docstring of discord.ext.tasks.loop:41
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/de/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/de/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ msgstr "The number of loops to do, ``None`` if it should be an infinite loop."
msgid "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."
msgstr "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."

msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."

msgid "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
msgstr "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
Expand Down
2 changes: 1 addition & 1 deletion docs/locales/en/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -2909,7 +2909,7 @@ msgstr ""
msgid ""
"The :class:`asyncio.AbstractEventLoop` to use for asynchronous "
"operations. Defaults to ``None``, in which case the default event loop is"
" used via :func:`asyncio.get_event_loop()`."
" used via :func:`asyncio.new_event_loop()`."
msgstr ""

#: 21cc11771cf14b8482b82ed348a0bcc9 discord.client.Client:17 of
Expand Down
2 changes: 1 addition & 1 deletion docs/locales/en/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ msgstr ""
#: 7e644a647eaa4981aad624c207683f5a discord.ext.tasks.loop:36 of
msgid ""
"The loop to use to register the task, if not given defaults to "
":func:`asyncio.get_event_loop`."
":func:`asyncio.new_event_loop`."
msgstr ""

#: 1b6f0ce5942646378838dbe0ab4fe0a0 discord.ext.tasks.loop:41 of
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/es/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/es/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ msgstr "The number of loops to do, ``None`` if it should be an infinite loop."
msgid "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."
msgstr "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."

msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."

msgid "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
msgstr "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/fr/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/fr/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ msgstr "Le nombre de boucles à faire, ``None`` si elle doit être une boucle in
msgid "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."
msgstr "Si vous voulez gérer les erreurs et redémarrer la tâche en utilisant un algorithme de back-off exponentiel similaire à celui utilisé dans :meth:`discord.Client.connect`."

msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgstr "La boucle à utiliser pour enregistrer la tâche, si elle n'est pas donnée par défaut à :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr "La boucle à utiliser pour enregistrer la tâche, si elle n'est pas donnée par défaut à :func:`asyncio.new_event_loop`."

msgid "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
msgstr "La fonction n'était pas une coroutine, une valeur invalide a été passée pour le paramètre ``time``, ou le paramètre ``time`` a été passé en conjonction avec des paramètres de temps relatifs."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/hi/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/hi/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ msgstr "The number of loops to do, ``None`` if it should be an infinite loop."
msgid "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."
msgstr "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."

msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."

msgid "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
msgstr "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/it/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/it/LC_MESSAGES/ext/tasks/index.po
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ msgstr "The number of loops to do, ``None`` if it should be an infinite loop."
msgid "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."
msgstr "Whether to handle errors and restart the task using an exponential back-off algorithm similar to the one used in :meth:`discord.Client.connect`."

msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.get_event_loop`."
msgid "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."
msgstr "The loop to use to register the task, if not given defaults to :func:`asyncio.new_event_loop`."

msgid "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
msgstr "The function was not a coroutine, an invalid value for the ``time`` parameter was passed, or ``time`` parameter was passed in conjunction with relative time parameters."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/ja/LC_MESSAGES/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
4 changes: 2 additions & 2 deletions docs/locales/ja/LC_MESSAGES/build/locales/api/clients.po
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
msgid "Allow disabling the message cache and change the default size to ``1000``."
msgstr "Allow disabling the message cache and change the default size to ``1000``."

msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.get_event_loop()`."
msgid "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."
msgstr "The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations. Defaults to ``None``, in which case the default event loop is used via :func:`asyncio.new_event_loop()`."

msgid "The connector to use for connection pooling."
msgstr "The connector to use for connection pooling."
Expand Down
Loading

0 comments on commit 4800b75

Please sign in to comment.