Skip to content

Commit

Permalink
Disallow creation of aiohttp objects without running event loop (#3539)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Jan 14, 2019
1 parent f590bfd commit 8fbe7a1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGES/3539.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disallow creation of aiohttp objects (``ClientSession``, ``Connector`` etc.) without running event loop.
10 changes: 2 additions & 8 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import re
import sys
import time
import warnings
import weakref
from collections import namedtuple
from contextlib import suppress
Expand Down Expand Up @@ -45,7 +44,7 @@
from yarl import URL

from . import hdrs
from .log import client_logger, internal_logger
from .log import client_logger
from .typedefs import PathLike # noqa

__all__ = ('BasicAuth', 'ChainMapProxy')
Expand Down Expand Up @@ -266,12 +265,7 @@ def get_running_loop(
if loop is None:
loop = asyncio.get_event_loop()
if not loop.is_running():
warnings.warn("The object should be created from async function",
DeprecationWarning, stacklevel=3)
if loop.get_debug():
internal_logger.warning(
"The object should be created from async function",
stack_info=True)
raise RuntimeError("The object should be created from async function")
return loop


Expand Down
4 changes: 3 additions & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,9 @@ def test_proxies_from_env_http_with_auth(mocker) -> None:


def test_get_running_loop_not_running(loop) -> None:
with pytest.warns(DeprecationWarning):
with pytest.raises(
RuntimeError,
match="The object should be created from async function"):
helpers.get_running_loop()


Expand Down

0 comments on commit 8fbe7a1

Please sign in to comment.