Skip to content

Commit

Permalink
Remove get_running_loop compat (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
pquentin committed Feb 9, 2024
1 parent b96d158 commit e114a73
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
4 changes: 2 additions & 2 deletions elastic_transport/_async_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
Union,
)

from ._compat import await_if_coro, get_running_loop
from ._compat import await_if_coro
from ._exceptions import (
ConnectionError,
ConnectionTimeout,
Expand Down Expand Up @@ -459,6 +459,6 @@ async def _async_call(self) -> None:
"""
if self._loop is not None:
return # Call at most once!
self._loop = get_running_loop()
self._loop = asyncio.get_running_loop()
if self._sniff_on_start:
await self.sniff(True)
12 changes: 0 additions & 12 deletions elastic_transport/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# specific language governing permissions and limitations
# under the License.

import asyncio
import inspect
import sys
from pathlib import Path
Expand All @@ -30,16 +29,6 @@
else:
from collections import OrderedDict as ordered_dict

try:
from asyncio import get_running_loop
except ImportError:

def get_running_loop() -> asyncio.AbstractEventLoop:
loop = asyncio.get_event_loop()
if not loop.is_running():
raise RuntimeError("no running event loop")
return loop


T = TypeVar("T")

Expand Down Expand Up @@ -118,7 +107,6 @@ def warn_stacklevel() -> int:

__all__ = [
"await_if_coro",
"get_running_loop",
"ordered_dict",
"quote",
"urlparse",
Expand Down
4 changes: 2 additions & 2 deletions elastic_transport/_node/_http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import warnings
from typing import Optional, Union

from .._compat import get_running_loop, warn_stacklevel
from .._compat import warn_stacklevel
from .._exceptions import ConnectionError, ConnectionTimeout, SecurityWarning, TlsError
from .._models import ApiResponseMeta, HttpHeaders, NodeConfig
from ..client_utils import DEFAULT, DefaultType, client_meta_version
Expand Down Expand Up @@ -248,7 +248,7 @@ def _create_aiohttp_session(self) -> None:
a chance to set AiohttpHttpNode.loop
"""
if self._loop is None:
self._loop = get_running_loop()
self._loop = asyncio.get_running_loop()
self.session = aiohttp.ClientSession(
headers=self.headers,
skip_auto_headers=("accept", "accept-encoding", "user-agent"),
Expand Down
5 changes: 2 additions & 3 deletions tests/async_/test_async_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
TransportWarning,
Urllib3HttpNode,
)
from elastic_transport._compat import get_running_loop
from elastic_transport._node._base import DEFAULT_USER_AGENT
from elastic_transport.client_utils import DEFAULT
from tests.conftest import AsyncDummyNode
Expand Down Expand Up @@ -532,7 +531,7 @@ async def test_sniffed_nodes_added_to_pool(async_sniff_callback):
NodeConfig("http", "localhost", 81),
]

loop = get_running_loop()
loop = asyncio.get_running_loop()
sniffed_at = 0.0

# Test that we accept both sync and async sniff_callbacks
Expand Down Expand Up @@ -650,7 +649,7 @@ async def sniff_callback(*_):
sniff_callback=sniff_callback,
)

loop = get_running_loop()
loop = asyncio.get_running_loop()
start = loop.time()

async def run_requests():
Expand Down

0 comments on commit e114a73

Please sign in to comment.