]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Enabling `ruff` C416 (#3001)
authorJames Braza <jamesbraza@gmail.com>
Wed, 13 Dec 2023 11:30:39 +0000 (06:30 -0500)
committerGitHub <noreply@github.com>
Wed, 13 Dec 2023 11:30:39 +0000 (11:30 +0000)
* Enabled C416 in ruff

* Ran ruff on all files

* Ran ruff format

* Update pyproject.toml

---------

Co-authored-by: Tom Christie <tom@tomchristie.com>
httpx/_content.py
httpx/_utils.py
tests/client/test_redirects.py
tests/models/test_requests.py
tests/models/test_responses.py
tests/test_content.py

index 0aaea33749a3d1ce41578c2ced4cce7d006c4b0f..cd0d17f17111df6df83d043bc93fd06e69ca299a 100644 (file)
@@ -105,7 +105,7 @@ class UnattachedStream(AsyncByteStream, SyncByteStream):
 
 
 def encode_content(
-    content: Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]]
+    content: Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]],
 ) -> Tuple[Dict[str, str], Union[SyncByteStream, AsyncByteStream]]:
     if isinstance(content, (bytes, str)):
         body = content.encode("utf-8") if isinstance(content, str) else content
index ba5807c0487223a5f1de40362120ad5e2594f691..a0bc2c5b6d8869fd99f984026526834eb62d72e5 100644 (file)
@@ -152,7 +152,7 @@ SENSITIVE_HEADERS = {"authorization", "proxy-authorization"}
 
 
 def obfuscate_sensitive_headers(
-    items: typing.Iterable[typing.Tuple[typing.AnyStr, typing.AnyStr]]
+    items: typing.Iterable[typing.Tuple[typing.AnyStr, typing.AnyStr]],
 ) -> typing.Iterator[typing.Tuple[typing.AnyStr, typing.AnyStr]]:
     for k, v in items:
         if to_str(k.lower()) in SENSITIVE_HEADERS:
index 6155df1447a293816fcac2fa2d71075f362933ec..f65827134c6e0c5426f678bba8cc546fcab14652 100644 (file)
@@ -345,7 +345,7 @@ def test_can_stream_if_no_redirect():
 class ConsumeBodyTransport(httpx.MockTransport):
     def handle_request(self, request: httpx.Request) -> httpx.Response:
         assert isinstance(request.stream, httpx.SyncByteStream)
-        [_ for _ in request.stream]
+        list(request.stream)
         return self.handler(request)  # type: ignore[return-value]
 
 
index d0d4f11d3284dd2c57a7f4e5941d4bbb2b8d9763..ad6d6705f20991bba0125fbeea973926d31e76ca 100644 (file)
@@ -82,7 +82,7 @@ def test_read_and_stream_data():
     request.read()
     assert request.stream is not None
     assert isinstance(request.stream, typing.Iterable)
-    content = b"".join([part for part in request.stream])
+    content = b"".join(list(request.stream))
     assert content == request.content
 
 
index 9177773a50480cd65926f7ec61e56965963c9d27..d639625825acda994deabe23326be01d49e9f54d 100644 (file)
@@ -397,19 +397,19 @@ def test_iter_raw():
 
 def test_iter_raw_with_chunksize():
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_raw(chunk_size=5)]
+    parts = list(response.iter_raw(chunk_size=5))
     assert parts == [b"Hello", b", wor", b"ld!"]
 
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_raw(chunk_size=7)]
+    parts = list(response.iter_raw(chunk_size=7))
     assert parts == [b"Hello, ", b"world!"]
 
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_raw(chunk_size=13)]
+    parts = list(response.iter_raw(chunk_size=13))
     assert parts == [b"Hello, world!"]
 
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_raw(chunk_size=20)]
+    parts = list(response.iter_raw(chunk_size=20))
     assert parts == [b"Hello, world!"]
 
 
@@ -422,7 +422,7 @@ def test_iter_raw_doesnt_return_empty_chunks():
 
     response = httpx.Response(200, content=streaming_body_with_empty_chunks())
 
-    parts = [part for part in response.iter_raw()]
+    parts = list(response.iter_raw())
     assert parts == [b"Hello, ", b"world!"]
 
 
@@ -445,7 +445,7 @@ def test_iter_raw_on_async():
     )
 
     with pytest.raises(RuntimeError):
-        [part for part in response.iter_raw()]
+        list(response.iter_raw())
 
 
 def test_close_on_async():
@@ -538,21 +538,21 @@ def test_iter_bytes():
 
 def test_iter_bytes_with_chunk_size():
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_bytes(chunk_size=5)]
+    parts = list(response.iter_bytes(chunk_size=5))
     assert parts == [b"Hello", b", wor", b"ld!"]
 
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_bytes(chunk_size=13)]
+    parts = list(response.iter_bytes(chunk_size=13))
     assert parts == [b"Hello, world!"]
 
     response = httpx.Response(200, content=streaming_body())
-    parts = [part for part in response.iter_bytes(chunk_size=20)]
+    parts = list(response.iter_bytes(chunk_size=20))
     assert parts == [b"Hello, world!"]
 
 
 def test_iter_bytes_with_empty_response():
     response = httpx.Response(200, content=b"")
-    parts = [part for part in response.iter_bytes()]
+    parts = list(response.iter_bytes())
     assert parts == []
 
 
@@ -565,7 +565,7 @@ def test_iter_bytes_doesnt_return_empty_chunks():
 
     response = httpx.Response(200, content=streaming_body_with_empty_chunks())
 
-    parts = [part for part in response.iter_bytes()]
+    parts = list(response.iter_bytes())
     assert parts == [b"Hello, ", b"world!"]
 
 
@@ -611,23 +611,23 @@ def test_iter_text():
 
 def test_iter_text_with_chunk_size():
     response = httpx.Response(200, content=b"Hello, world!")
-    parts = [part for part in response.iter_text(chunk_size=5)]
+    parts = list(response.iter_text(chunk_size=5))
     assert parts == ["Hello", ", wor", "ld!"]
 
     response = httpx.Response(200, content=b"Hello, world!!")
-    parts = [part for part in response.iter_text(chunk_size=7)]
+    parts = list(response.iter_text(chunk_size=7))
     assert parts == ["Hello, ", "world!!"]
 
     response = httpx.Response(200, content=b"Hello, world!")
-    parts = [part for part in response.iter_text(chunk_size=7)]
+    parts = list(response.iter_text(chunk_size=7))
     assert parts == ["Hello, ", "world!"]
 
     response = httpx.Response(200, content=b"Hello, world!")
-    parts = [part for part in response.iter_text(chunk_size=13)]
+    parts = list(response.iter_text(chunk_size=13))
     assert parts == ["Hello, world!"]
 
     response = httpx.Response(200, content=b"Hello, world!")
-    parts = [part for part in response.iter_text(chunk_size=20)]
+    parts = list(response.iter_text(chunk_size=20))
     assert parts == ["Hello, world!"]
 
 
@@ -664,7 +664,7 @@ def test_iter_lines():
         200,
         content=b"Hello,\nworld!",
     )
-    content = [line for line in response.iter_lines()]
+    content = list(response.iter_lines())
     assert content == ["Hello,", "world!"]
 
 
index a4d5f7a1fcc8fa7d6d533313c419692779c7a059..21c92dd799318f16bd7b754ef444b851d2968d21 100644 (file)
@@ -15,7 +15,7 @@ async def test_empty_content():
     assert isinstance(request.stream, httpx.SyncByteStream)
     assert isinstance(request.stream, httpx.AsyncByteStream)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}
@@ -29,7 +29,7 @@ async def test_bytes_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}
@@ -42,7 +42,7 @@ async def test_bytes_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}
@@ -56,7 +56,7 @@ async def test_bytesio_content():
     assert isinstance(request.stream, typing.Iterable)
     assert not isinstance(request.stream, typing.AsyncIterable)
 
-    content = b"".join([part for part in request.stream])
+    content = b"".join(list(request.stream))
 
     assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}
     assert content == b"Hello, world!"
@@ -100,7 +100,7 @@ async def test_iterator_content():
     assert isinstance(request.stream, typing.Iterable)
     assert not isinstance(request.stream, typing.AsyncIterable)
 
-    content = b"".join([part for part in request.stream])
+    content = b"".join(list(request.stream))
 
     assert request.headers == {
         "Host": "www.example.com",
@@ -109,7 +109,7 @@ async def test_iterator_content():
     assert content == b"Hello, world!"
 
     with pytest.raises(httpx.StreamConsumed):
-        [part for part in request.stream]
+        list(request.stream)
 
     # Support 'data' for compat with requests.
     with pytest.warns(DeprecationWarning):
@@ -117,7 +117,7 @@ async def test_iterator_content():
     assert isinstance(request.stream, typing.Iterable)
     assert not isinstance(request.stream, typing.AsyncIterable)
 
-    content = b"".join([part for part in request.stream])
+    content = b"".join(list(request.stream))
 
     assert request.headers == {
         "Host": "www.example.com",
@@ -168,7 +168,7 @@ async def test_json_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -186,7 +186,7 @@ async def test_urlencoded_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -204,7 +204,7 @@ async def test_urlencoded_boolean():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -222,7 +222,7 @@ async def test_urlencoded_none():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -240,7 +240,7 @@ async def test_urlencoded_list():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -265,7 +265,7 @@ async def test_multipart_files_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -304,7 +304,7 @@ async def test_multipart_data_and_files_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -348,7 +348,7 @@ async def test_empty_request():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}
@@ -375,7 +375,7 @@ async def test_multipart_multiple_files_single_input_content():
     assert isinstance(request.stream, typing.Iterable)
     assert isinstance(request.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in request.stream])
+    sync_content = b"".join(list(request.stream))
     async_content = b"".join([part async for part in request.stream])
 
     assert request.headers == {
@@ -421,7 +421,7 @@ async def test_response_empty_content():
     assert isinstance(response.stream, typing.Iterable)
     assert isinstance(response.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in response.stream])
+    sync_content = b"".join(list(response.stream))
     async_content = b"".join([part async for part in response.stream])
 
     assert response.headers == {}
@@ -435,7 +435,7 @@ async def test_response_bytes_content():
     assert isinstance(response.stream, typing.Iterable)
     assert isinstance(response.stream, typing.AsyncIterable)
 
-    sync_content = b"".join([part for part in response.stream])
+    sync_content = b"".join(list(response.stream))
     async_content = b"".join([part async for part in response.stream])
 
     assert response.headers == {"Content-Length": "13"}
@@ -453,13 +453,13 @@ async def test_response_iterator_content():
     assert isinstance(response.stream, typing.Iterable)
     assert not isinstance(response.stream, typing.AsyncIterable)
 
-    content = b"".join([part for part in response.stream])
+    content = b"".join(list(response.stream))
 
     assert response.headers == {"Transfer-Encoding": "chunked"}
     assert content == b"Hello, world!"
 
     with pytest.raises(httpx.StreamConsumed):
-        [part for part in response.stream]
+        list(response.stream)
 
 
 @pytest.mark.anyio