Enabling `ruff` C416 (#3001)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* Enabled C416 in ruff * Ran ruff on all files * Ran ruff format * Update pyproject.toml ---------
authored by James Braza · committed by GitHub · parent 2c51edd · Browse files · 6 files·+41 added−41 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Tom Christie <tom@tomchristie.com>
Diff stats
6 files+41 added−41 removed
- tests:+39 added−39 removed
- other:+2 added−2 removed
Provenance
- Commit
2318fd8- Tree
dbd3513- Author
James Braza <jamesbraza@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
2c51edd
6 files changed+41 added−41 removed
modified:httpx/_content.py+1 added-1 removed
103 unmodified lines104 yield b"" # pragma: no cover105 106 107 def encode_content(108- content: Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]]108+ content: Union[str, bytes, Iterable[bytes], AsyncIterable[bytes]],109 ) -> Tuple[Dict[str, str], Union[SyncByteStream, AsyncByteStream]]:110 if isinstance(content, (bytes, str)):111 body = content.encode("utf-8") if isinstance(content, str) else content112 content_length = len(body)126 unmodified linesmodified:httpx/_utils.py+1 added-1 removed
150 unmodified lines151 SENSITIVE_HEADERS = {"authorization", "proxy-authorization"}152 153 154 def obfuscate_sensitive_headers(155- items: typing.Iterable[typing.Tuple[typing.AnyStr, typing.AnyStr]]155+ items: typing.Iterable[typing.Tuple[typing.AnyStr, typing.AnyStr]],156 ) -> typing.Iterator[typing.Tuple[typing.AnyStr, typing.AnyStr]]:157 for k, v in items:158 if to_str(k.lower()) in SENSITIVE_HEADERS:159 v = to_bytes_or_str("[secure]", match_type_of=v)283 unmodified linesmodified:tests/client/test_redirects.py+1 added-1 removed
343 unmodified lines344 345 class ConsumeBodyTransport(httpx.MockTransport):346 def handle_request(self, request: httpx.Request) -> httpx.Response:347 assert isinstance(request.stream, httpx.SyncByteStream)348- [_ for _ in request.stream]348+ list(request.stream)349 return self.handler(request) # type: ignore[return-value]350 351 352 def test_cannot_redirect_streaming_body():95 unmodified linesmodified:tests/models/test_requests.py+1 added-1 removed
80 unmodified lines81 request = httpx.Request("POST", "http://example.org", json={"test": 123})82 request.read()83 assert request.stream is not None84 assert isinstance(request.stream, typing.Iterable)85- content = b"".join([part for part in request.stream])85+ content = b"".join(list(request.stream))86 assert content == request.content87 88 89 @pytest.mark.anyio139 unmodified linesmodified:tests/models/test_responses.py+17 added-17 removed
395 unmodified lines396 397 398 def test_iter_raw_with_chunksize():399 response = httpx.Response(200, content=streaming_body())400- parts = [part for part in response.iter_raw(chunk_size=5)]400+ parts = list(response.iter_raw(chunk_size=5))401 assert parts == [b"Hello", b", wor", b"ld!"]402 403 response = httpx.Response(200, content=streaming_body())404- parts = [part for part in response.iter_raw(chunk_size=7)]404+ parts = list(response.iter_raw(chunk_size=7))405 assert parts == [b"Hello, ", b"world!"]406 407 response = httpx.Response(200, content=streaming_body())408- parts = [part for part in response.iter_raw(chunk_size=13)]408+ parts = list(response.iter_raw(chunk_size=13))409 assert parts == [b"Hello, world!"]410 411 response = httpx.Response(200, content=streaming_body())412- parts = [part for part in response.iter_raw(chunk_size=20)]412+ parts = list(response.iter_raw(chunk_size=20))413 assert parts == [b"Hello, world!"]414 415 416 def test_iter_raw_doesnt_return_empty_chunks():4 unmodified lines421 yield b""422 423 response = httpx.Response(200, content=streaming_body_with_empty_chunks())424 425- parts = [part for part in response.iter_raw()]425+ parts = list(response.iter_raw())426 assert parts == [b"Hello, ", b"world!"]427 428 429 def test_iter_raw_on_iterable():14 unmodified lines444 content=async_streaming_body(),445 )446 447 with pytest.raises(RuntimeError):448- [part for part in response.iter_raw()]448+ list(response.iter_raw())449 450 451 def test_close_on_async():452 response = httpx.Response(84 unmodified lines537 538 539 def test_iter_bytes_with_chunk_size():540 response = httpx.Response(200, content=streaming_body())541- parts = [part for part in response.iter_bytes(chunk_size=5)]541+ parts = list(response.iter_bytes(chunk_size=5))542 assert parts == [b"Hello", b", wor", b"ld!"]543 544 response = httpx.Response(200, content=streaming_body())545- parts = [part for part in response.iter_bytes(chunk_size=13)]545+ parts = list(response.iter_bytes(chunk_size=13))546 assert parts == [b"Hello, world!"]547 548 response = httpx.Response(200, content=streaming_body())549- parts = [part for part in response.iter_bytes(chunk_size=20)]549+ parts = list(response.iter_bytes(chunk_size=20))550 assert parts == [b"Hello, world!"]551 552 553 def test_iter_bytes_with_empty_response():554 response = httpx.Response(200, content=b"")555- parts = [part for part in response.iter_bytes()]555+ parts = list(response.iter_bytes())556 assert parts == []557 558 559 def test_iter_bytes_doesnt_return_empty_chunks():4 unmodified lines564 yield b""565 566 response = httpx.Response(200, content=streaming_body_with_empty_chunks())567 568- parts = [part for part in response.iter_bytes()]568+ parts = list(response.iter_bytes())569 assert parts == [b"Hello, ", b"world!"]570 571 572 @pytest.mark.anyio37 unmodified lines610 611 612 def test_iter_text_with_chunk_size():613 response = httpx.Response(200, content=b"Hello, world!")614- parts = [part for part in response.iter_text(chunk_size=5)]614+ parts = list(response.iter_text(chunk_size=5))615 assert parts == ["Hello", ", wor", "ld!"]616 617 response = httpx.Response(200, content=b"Hello, world!!")618- parts = [part for part in response.iter_text(chunk_size=7)]618+ parts = list(response.iter_text(chunk_size=7))619 assert parts == ["Hello, ", "world!!"]620 621 response = httpx.Response(200, content=b"Hello, world!")622- parts = [part for part in response.iter_text(chunk_size=7)]622+ parts = list(response.iter_text(chunk_size=7))623 assert parts == ["Hello, ", "world!"]624 625 response = httpx.Response(200, content=b"Hello, world!")626- parts = [part for part in response.iter_text(chunk_size=13)]626+ parts = list(response.iter_text(chunk_size=13))627 assert parts == ["Hello, world!"]628 629 response = httpx.Response(200, content=b"Hello, world!")630- parts = [part for part in response.iter_text(chunk_size=20)]630+ parts = list(response.iter_text(chunk_size=20))631 assert parts == ["Hello, world!"]632 633 634 @pytest.mark.anyio28 unmodified lines663 response = httpx.Response(664 200,665 content=b"Hello,\nworld!",666 )667- content = [line for line in response.iter_lines()]667+ content = list(response.iter_lines())668 assert content == ["Hello,", "world!"]669 670 671 @pytest.mark.anyio366 unmodified linesmodified:tests/test_content.py+20 added-20 removed
13 unmodified lines14 request = httpx.Request(method, url)15 assert isinstance(request.stream, httpx.SyncByteStream)16 assert isinstance(request.stream, httpx.AsyncByteStream)17 18- sync_content = b"".join([part for part in request.stream])18+ sync_content = b"".join(list(request.stream))19 async_content = b"".join([part async for part in request.stream])20 21 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}22 assert sync_content == b""5 unmodified lines28 request = httpx.Request(method, url, content=b"Hello, world!")29 assert isinstance(request.stream, typing.Iterable)30 assert isinstance(request.stream, typing.AsyncIterable)31 32- sync_content = b"".join([part for part in request.stream])32+ sync_content = b"".join(list(request.stream))33 async_content = b"".join([part async for part in request.stream])34 35 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}36 assert sync_content == b"Hello, world!"4 unmodified lines41 request = httpx.Request(method, url, data=b"Hello, world!") # type: ignore42 assert isinstance(request.stream, typing.Iterable)43 assert isinstance(request.stream, typing.AsyncIterable)44 45- sync_content = b"".join([part for part in request.stream])45+ sync_content = b"".join(list(request.stream))46 async_content = b"".join([part async for part in request.stream])47 48 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}49 assert sync_content == b"Hello, world!"5 unmodified lines55 request = httpx.Request(method, url, content=io.BytesIO(b"Hello, world!"))56 assert isinstance(request.stream, typing.Iterable)57 assert not isinstance(request.stream, typing.AsyncIterable)58 59- content = b"".join([part for part in request.stream])59+ content = b"".join(list(request.stream))60 61 assert request.headers == {"Host": "www.example.com", "Content-Length": "13"}62 assert content == b"Hello, world!"63 35 unmodified lines99 request = httpx.Request(method, url, content=hello_world())100 assert isinstance(request.stream, typing.Iterable)101 assert not isinstance(request.stream, typing.AsyncIterable)102 103- content = b"".join([part for part in request.stream])103+ content = b"".join(list(request.stream))104 105 assert request.headers == {106 "Host": "www.example.com",107 "Transfer-Encoding": "chunked",108 }109 assert content == b"Hello, world!"110 111 with pytest.raises(httpx.StreamConsumed):112- [part for part in request.stream]112+ list(request.stream)113 114 # Support 'data' for compat with requests.115 with pytest.warns(DeprecationWarning):116 request = httpx.Request(method, url, data=hello_world()) # type: ignore117 assert isinstance(request.stream, typing.Iterable)118 assert not isinstance(request.stream, typing.AsyncIterable)119 120- content = b"".join([part for part in request.stream])120+ content = b"".join(list(request.stream))121 122 assert request.headers == {123 "Host": "www.example.com",124 "Transfer-Encoding": "chunked",42 unmodified lines167 request = httpx.Request(method, url, json={"Hello": "world!"})168 assert isinstance(request.stream, typing.Iterable)169 assert isinstance(request.stream, typing.AsyncIterable)170 171- sync_content = b"".join([part for part in request.stream])171+ sync_content = b"".join(list(request.stream))172 async_content = b"".join([part async for part in request.stream])173 174 assert request.headers == {175 "Host": "www.example.com",9 unmodified lines185 request = httpx.Request(method, url, data={"Hello": "world!"})186 assert isinstance(request.stream, typing.Iterable)187 assert isinstance(request.stream, typing.AsyncIterable)188 189- sync_content = b"".join([part for part in request.stream])189+ sync_content = b"".join(list(request.stream))190 async_content = b"".join([part async for part in request.stream])191 192 assert request.headers == {193 "Host": "www.example.com",9 unmodified lines203 request = httpx.Request(method, url, data={"example": True})204 assert isinstance(request.stream, typing.Iterable)205 assert isinstance(request.stream, typing.AsyncIterable)206 207- sync_content = b"".join([part for part in request.stream])207+ sync_content = b"".join(list(request.stream))208 async_content = b"".join([part async for part in request.stream])209 210 assert request.headers == {211 "Host": "www.example.com",9 unmodified lines221 request = httpx.Request(method, url, data={"example": None})222 assert isinstance(request.stream, typing.Iterable)223 assert isinstance(request.stream, typing.AsyncIterable)224 225- sync_content = b"".join([part for part in request.stream])225+ sync_content = b"".join(list(request.stream))226 async_content = b"".join([part async for part in request.stream])227 228 assert request.headers == {229 "Host": "www.example.com",9 unmodified lines239 request = httpx.Request(method, url, data={"example": ["a", 1, True]})240 assert isinstance(request.stream, typing.Iterable)241 assert isinstance(request.stream, typing.AsyncIterable)242 243- sync_content = b"".join([part for part in request.stream])243+ sync_content = b"".join(list(request.stream))244 async_content = b"".join([part async for part in request.stream])245 246 assert request.headers == {247 "Host": "www.example.com",16 unmodified lines264 )265 assert isinstance(request.stream, typing.Iterable)266 assert isinstance(request.stream, typing.AsyncIterable)267 268- sync_content = b"".join([part for part in request.stream])268+ sync_content = b"".join(list(request.stream))269 async_content = b"".join([part async for part in request.stream])270 271 assert request.headers == {272 "Host": "www.example.com",30 unmodified lines303 request = httpx.Request(method, url, data=data, files=files, headers=headers)304 assert isinstance(request.stream, typing.Iterable)305 assert isinstance(request.stream, typing.AsyncIterable)306 307- sync_content = b"".join([part for part in request.stream])307+ sync_content = b"".join(list(request.stream))308 async_content = b"".join([part async for part in request.stream])309 310 assert request.headers == {311 "Host": "www.example.com",35 unmodified lines347 request = httpx.Request(method, url, data={}, files={})348 assert isinstance(request.stream, typing.Iterable)349 assert isinstance(request.stream, typing.AsyncIterable)350 351- sync_content = b"".join([part for part in request.stream])351+ sync_content = b"".join(list(request.stream))352 async_content = b"".join([part async for part in request.stream])353 354 assert request.headers == {"Host": "www.example.com", "Content-Length": "0"}355 assert sync_content == b""18 unmodified lines374 request = httpx.Request(method, url, files=files, headers=headers)375 assert isinstance(request.stream, typing.Iterable)376 assert isinstance(request.stream, typing.AsyncIterable)377 378- sync_content = b"".join([part for part in request.stream])378+ sync_content = b"".join(list(request.stream))379 async_content = b"".join([part async for part in request.stream])380 381 assert request.headers == {382 "Host": "www.example.com",37 unmodified lines420 response = httpx.Response(200)421 assert isinstance(response.stream, typing.Iterable)422 assert isinstance(response.stream, typing.AsyncIterable)423 424- sync_content = b"".join([part for part in response.stream])424+ sync_content = b"".join(list(response.stream))425 async_content = b"".join([part async for part in response.stream])426 427 assert response.headers == {}428 assert sync_content == b""5 unmodified lines434 response = httpx.Response(200, content=b"Hello, world!")435 assert isinstance(response.stream, typing.Iterable)436 assert isinstance(response.stream, typing.AsyncIterable)437 438- sync_content = b"".join([part for part in response.stream])438+ sync_content = b"".join(list(response.stream))439 async_content = b"".join([part async for part in response.stream])440 441 assert response.headers == {"Content-Length": "13"}442 assert sync_content == b"Hello, world!"9 unmodified lines452 response = httpx.Response(200, content=hello_world())453 assert isinstance(response.stream, typing.Iterable)454 assert not isinstance(response.stream, typing.AsyncIterable)455 456- content = b"".join([part for part in response.stream])456+ content = b"".join(list(response.stream))457 458 assert response.headers == {"Transfer-Encoding": "chunked"}459 assert content == b"Hello, world!"460 461 with pytest.raises(httpx.StreamConsumed):462- [part for part in response.stream]462+ list(response.stream)463 464 465 @pytest.mark.anyio466 async def test_response_aiterator_content():20 unmodified lines