Skip to content

Commit

Permalink
Deprecate obsolete timeout sessions in ClientSession (#3438)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Dec 8, 2018
1 parent 117cbe1 commit dfdf510
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/3438.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecate obsolete ``read_timeout`` and ``conn_timeout`` in ``ClientSession`` constructor.
8 changes: 8 additions & 0 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,18 @@ def __init__(self, *, connector: Optional[BaseConnector]=None,
if timeout is sentinel:
self._timeout = DEFAULT_TIMEOUT
if read_timeout is not sentinel:
warnings.warn("read_timeout is deprecated, "
"use timeout argument instead",
DeprecationWarning,
stacklevel=2)
self._timeout = attr.evolve(self._timeout, total=read_timeout)
if conn_timeout is not None:
self._timeout = attr.evolve(self._timeout,
connect=conn_timeout)
warnings.warn("conn_timeout is deprecated, "
"use timeout argument instead",
DeprecationWarning,
stacklevel=2)
else:
self._timeout = timeout # type: ignore
if read_timeout is not sentinel:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,10 @@ async def handler(request):
app.router.add_route('GET', '/', handler)

conn = aiohttp.TCPConnector()
client = await aiohttp_client(app, connector=conn, read_timeout=0.01)
client = await aiohttp_client(
app,
connector=conn,
timeout=aiohttp.ClientTimeout(sock_read=0.01))

with pytest.raises(asyncio.TimeoutError):
await client.get('/')
Expand Down
5 changes: 4 additions & 1 deletion tests/test_client_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,10 @@ async def test_client_session_timeout_args(loop) -> None:
session1 = ClientSession(loop=loop)
assert session1._timeout == client.DEFAULT_TIMEOUT

session2 = ClientSession(loop=loop, read_timeout=20*60, conn_timeout=30*60)
with pytest.warns(DeprecationWarning):
session2 = ClientSession(loop=loop,
read_timeout=20*60,
conn_timeout=30*60)
assert session2._timeout == client.ClientTimeout(total=20*60,
connect=30*60)

Expand Down

0 comments on commit dfdf510

Please sign in to comment.