Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ line-length = 120
exclude = ["src/httpcore2/httpcore2/_sync", "tests/httpcore2/_sync"]

[tool.ruff.lint]
select = ["E", "F", "W", "I", "B", "PIE"]
select = ["B", "C4", "E", "F", "I", "PERF", "PIE", "W"]
ignore = ["B904", "B028"]

[tool.ruff.lint.isort]
Expand All @@ -58,6 +58,8 @@ known-first-party = ["httpx2", "httpcore2"]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F403", "F405"]
"src/httpcore2/httpcore2/_async/connection.py" = ["PERF203"]
"src/httpcore2/httpcore2/_async/http_proxy.py" = ["C401"]

[tool.mypy]
ignore_missing_imports = true
Expand Down
4 changes: 2 additions & 2 deletions src/httpcore2/httpcore2/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def include_request_headers(
url: "URL",
content: None | bytes | typing.Iterable[bytes] | typing.AsyncIterable[bytes],
) -> list[tuple[bytes, bytes]]:
headers_set = set(k.lower() for k, v in headers)
headers_set = {k.lower() for k, v in headers}

if b"host" not in headers_set:
default_port = DEFAULT_PORTS.get(url.scheme)
Expand Down Expand Up @@ -404,7 +404,7 @@ def read(self) -> bytes:
"You should use 'await response.aread()' instead."
)
if not hasattr(self, "_content"):
self._content = b"".join([part for part in self.iter_stream()])
self._content = b"".join(list(self.iter_stream()))
return self._content

def iter_stream(self) -> typing.Iterator[bytes]:
Expand Down
3 changes: 1 addition & 2 deletions src/httpx2/httpx2/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def format_certificate(cert: _PeerCertRetDictType) -> str: # pragma: no cover
lines.append(f"* {key}:")
for item in value:
if key in ("subject", "issuer"):
for sub_item in item:
lines.append(f"* {sub_item[0]}: {sub_item[1]!r}")
lines.extend(f"* {sub_item[0]}: {sub_item[1]!r}" for sub_item in item)
elif isinstance(item, tuple) and len(item) == 2:
lines.append(f"* {item[0]}: {item[1]!r}")
else:
Expand Down
2 changes: 1 addition & 1 deletion src/httpx2/httpx2/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def encoding(self) -> str:
try:
key.decode(encoding)
value.decode(encoding)
except UnicodeDecodeError:
except UnicodeDecodeError: # noqa: PERF203
break
else:
# The else block runs if 'break' did not occur, meaning
Expand Down
2 changes: 1 addition & 1 deletion tests/httpcore2/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_response_sync_read():
def test_response_sync_streaming():
stream = ByteIterator([b"Hello, ", b"world!"])
response = httpcore2.Response(200, content=stream)
content = b"".join([chunk for chunk in response.iter_stream()])
content = b"".join(list(response.iter_stream()))
assert content == b"Hello, world!"

# We streamed the response rather than reading it, so .content is not available.
Expand Down
4 changes: 2 additions & 2 deletions tests/httpx2/models/test_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ def test_sensitive_headers(header):
],
)
def test_obfuscate_sensitive_headers(headers, output):
as_dict = {k: v for k, v in output}
headers_class = httpx2.Headers({k: v for k, v in headers})
as_dict = dict(output)
headers_class = httpx2.Headers(dict(headers))
assert repr(headers_class) == f"Headers({as_dict!r})"


Expand Down
4 changes: 1 addition & 3 deletions tests/httpx2/models/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,7 @@ async def test_aiter_lines():
content=b"Hello,\nworld!",
)

content = []
async for line in response.aiter_lines():
content.append(line)
content = [line async for line in response.aiter_lines()]
assert content == ["Hello,", "world!"]


Expand Down
Loading