Skip to content

Commit 4800b75

Browse files
committed
fix: Remove deprecated get_event_loop() in favor of new_event_loop()
1 parent 72ba1b1 commit 4800b75

File tree

33 files changed

+58
-59
lines changed

33 files changed

+58
-59
lines changed

discord/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Client:
133133
loop: Optional[:class:`asyncio.AbstractEventLoop`]
134134
The :class:`asyncio.AbstractEventLoop` to use for asynchronous operations.
135135
Defaults to ``None``, in which case the default event loop is used via
136-
:func:`asyncio.get_event_loop()`.
136+
:func:`asyncio.new_event_loop()`.
137137
connector: Optional[:class:`aiohttp.BaseConnector`]
138138
The connector to use for connection pooling.
139139
proxy: Optional[:class:`str`]
@@ -227,7 +227,7 @@ def __init__(
227227
# self.ws is set in the connect method
228228
self.ws: DiscordWebSocket = None # type: ignore
229229
self.loop: asyncio.AbstractEventLoop = (
230-
asyncio.get_event_loop() if loop is None else loop
230+
asyncio.new_event_loop() if loop is None else loop
231231
)
232232
self._listeners: dict[str, list[tuple[asyncio.Future, Callable[..., bool]]]] = (
233233
{}

discord/ext/commands/cooldowns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class _Semaphore:
308308

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

314314
def __repr__(self) -> str:

discord/ext/tasks/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def start(self, *args: Any, **kwargs: Any) -> asyncio.Task[None]:
330330
args = (self._injected, *args)
331331

332332
if self.loop is MISSING:
333-
self.loop = asyncio.get_event_loop()
333+
self.loop = asyncio.new_event_loop()
334334

335335
self._task = self.loop.create_task(self._loop(*args, **kwargs))
336336
return self._task
@@ -771,7 +771,7 @@ def loop(
771771
one used in :meth:`discord.Client.connect`.
772772
loop: :class:`asyncio.AbstractEventLoop`
773773
The loop to use to register the task, if not given
774-
defaults to :func:`asyncio.get_event_loop`.
774+
defaults to :func:`asyncio.new_event_loop`.
775775
776776
Raises
777777
------

discord/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def __init__(
173173
unsync_clock: bool = True,
174174
) -> None:
175175
self.loop: asyncio.AbstractEventLoop = (
176-
asyncio.get_event_loop() if loop is None else loop
176+
asyncio.new_event_loop() if loop is None else loop
177177
)
178178
self.connector = connector
179179
self.__session: aiohttp.ClientSession = MISSING # filled in static_login

discord/player.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ async def probe(
572572
)
573573

574574
codec = bitrate = None
575-
loop = asyncio.get_event_loop()
575+
loop = asyncio.get_running_loop()
576576
try:
577577
codec, bitrate = await loop.run_in_executor(None, lambda: probefunc(source, executable)) # type: ignore
578578
except Exception:

discord/ui/modal.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ def __init__(
6262
self._title = title
6363
self._children: list[InputText] = list(children)
6464
self._weights = _ModalWeights(self._children)
65-
loop = asyncio.get_running_loop()
66-
self._stopped: asyncio.Future[bool] = loop.create_future()
65+
self.loop = asyncio.get_running_loop()
66+
self._stopped: asyncio.Future[bool] = self.loop.create_future()
6767
self.__cancel_callback: Callable[[Modal], None] | None = None
6868
self.__timeout_expiry: float | None = None
6969
self.__timeout_task: asyncio.Task[None] | None = None
70-
self.loop = asyncio.get_event_loop()
7170

7271
def _start_listening_from_store(self, store: ModalStore) -> None:
7372
self.__cancel_callback = partial(store.remove_modal)

docs/build/locales/api/clients.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3706,7 +3706,7 @@ msgstr ""
37063706

37073707
#: ../../../discord/client.py:docstring of discord.client.Client:13
37083708
#: 6c88dd4b014e4fd68019bf91e0e79449
3709-
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()`."
3709+
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()`."
37103710
msgstr ""
37113711

37123712
#: ../../../discord/client.py:docstring of discord.client.Client:17

docs/build/locales/ext/tasks/index.pot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ msgstr ""
516516

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

522522
#: ../../../discord/ext/tasks/__init__.py:docstring of discord.ext.tasks.loop:41

docs/locales/de/LC_MESSAGES/api/clients.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,8 @@ msgstr "The maximum number of messages to store in the internal message cache. T
14271427
msgid "Allow disabling the message cache and change the default size to ``1000``."
14281428
msgstr "Allow disabling the message cache and change the default size to ``1000``."
14291429

1430-
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()`."
1431-
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()`."
1430+
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()`."
1431+
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()`."
14321432

14331433
msgid "The connector to use for connection pooling."
14341434
msgstr "The connector to use for connection pooling."

docs/locales/de/LC_MESSAGES/ext/tasks/index.po

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ msgstr "The number of loops to do, ``None`` if it should be an infinite loop."
272272
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`."
273273
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`."
274274

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

278278
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."
279279
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."

0 commit comments

Comments
 (0)