Skip to content

Commit 9f94def

Browse files
Rename 'next' to 'anext' on Response
1 parent e30ec85 commit 9f94def

4 files changed

Lines changed: 14 additions & 7 deletions

File tree

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
* `def .aiter_text()` - **async text iterator**
6969
* `def .aiter_lines()` - **async text iterator**
7070
* `def .close()` - **None**
71-
* `def .next()` - **Response**
71+
* `def .anext()` - **Response**
7272

7373
## `Request`
7474

httpx/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,12 @@ async def send_handling_redirects(
476476

477477
if not allow_redirects:
478478
response.call_next = functools.partial(
479-
self.send_handling_redirects,
479+
# NOTE: not using 'self.send_handling_redirects' here, because
480+
# 'call_next' must reference a function (instead
481+
# of a method). This ensures that 'inspect.iscoroutinefunction()'
482+
# checks behave properly.
483+
Client.send_handling_redirects,
484+
self,
480485
request=request,
481486
auth=auth,
482487
verify=verify,

httpx/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import cgi
22
import datetime
33
import email.message
4+
import inspect
45
import json as jsonlib
56
import typing
67
import urllib.request
@@ -922,13 +923,14 @@ async def aiter_raw(self) -> typing.AsyncIterator[bytes]:
922923
yield part
923924
await self.close()
924925

925-
async def next(self) -> "Response":
926+
async def anext(self) -> "Response":
926927
"""
927928
Get the next response from a redirect response.
928929
"""
929930
if not self.is_redirect:
930931
raise NotRedirectResponse()
931932
assert self.call_next is not None
933+
assert inspect.iscoroutinefunction(self.call_next)
932934
return await self.call_next()
933935

934936
async def close(self) -> None:

tests/client/test_redirects.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async def test_no_redirect():
110110
response = await client.get(url)
111111
assert response.status_code == 200
112112
with pytest.raises(NotRedirectResponse):
113-
await response.next()
113+
await response.anext()
114114

115115

116116
@pytest.mark.usefixtures("async_environment")
@@ -151,7 +151,7 @@ async def test_disallow_redirects():
151151
assert response.is_redirect is True
152152
assert len(response.history) == 0
153153

154-
response = await response.next()
154+
response = await response.anext()
155155
assert response.status_code == codes.OK
156156
assert response.url == URL("https://example.org/")
157157
assert response.is_redirect is False
@@ -216,7 +216,7 @@ async def test_too_many_redirects_calling_next():
216216
response = await client.get(url, allow_redirects=False)
217217
with pytest.raises(TooManyRedirects):
218218
while response.is_redirect:
219-
response = await response.next()
219+
response = await response.anext()
220220

221221

222222
@pytest.mark.usefixtures("async_environment")
@@ -233,7 +233,7 @@ async def test_redirect_loop_calling_next():
233233
response = await client.get(url, allow_redirects=False)
234234
with pytest.raises(RedirectLoop):
235235
while response.is_redirect:
236-
response = await response.next()
236+
response = await response.anext()
237237

238238

239239
@pytest.mark.usefixtures("async_environment")

0 commit comments

Comments
 (0)