Skip to content

Commit 5b2a653

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 2854331 commit 5b2a653

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/pip/_internal/network/rfc9457.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
RFC9457_CONTENT_TYPE = "application/problem+json"
2121

22+
2223
@dataclass
2324
class ProblemDetails:
2425
"""Represents an RFC 9457 Problem Details object.
@@ -81,7 +82,9 @@ def parse_problem_details(response: Response) -> ProblemDetails | None:
8182
if problem.status is None:
8283
problem.status = response.status_code
8384

84-
logger.debug("Parsed problem details: status=%s, title=%s", problem.status, problem.title)
85+
logger.debug(
86+
"Parsed problem details: status=%s, title=%s", problem.status, problem.title
87+
)
8588
return problem
8689

8790
except (json.JSONDecodeError, ValueError):

tests/unit/test_network_rfc9457.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
parse_problem_details,
1212
)
1313
from pip._internal.network.utils import raise_for_status
14+
1415
from tests.lib.requests_mocks import MockResponse
1516

1617

@@ -28,11 +29,13 @@ def test_from_dict(self) -> None:
2829
assert problem.detail == "Resource not found"
2930

3031
def test_from_json(self) -> None:
31-
json_str = json.dumps({
32-
"status": 404,
33-
"title": "Not Found",
34-
"detail": "Resource not found",
35-
})
32+
json_str = json.dumps(
33+
{
34+
"status": 404,
35+
"title": "Not Found",
36+
"detail": "Resource not found",
37+
}
38+
)
3639

3740
problem = ProblemDetails.from_json(json_str)
3841
assert problem.status == 404
@@ -51,6 +54,7 @@ def test_string_representation(self) -> None:
5154
assert "403" in str_repr
5255
assert "API token" in str_repr
5356

57+
5458
class TestIsProblemDetailsResponse:
5559
def test_detects_problem_json_content_type(self) -> None:
5660
resp = MockResponse(b"")
@@ -76,6 +80,7 @@ def test_does_not_detect_without_content_type(self) -> None:
7680

7781
assert is_problem_details_response(resp) is False
7882

83+
7984
class TestParseProblemDetails:
8085
def test_parses_valid_problem_details(self) -> None:
8186
problem_data = {
@@ -107,6 +112,7 @@ def test_handles_malformed_json(self) -> None:
107112
problem = parse_problem_details(resp)
108113
assert problem is None
109114

115+
110116
@pytest.mark.parametrize(
111117
"status_code, title, detail",
112118
[
@@ -115,7 +121,6 @@ def test_handles_malformed_json(self) -> None:
115121
(403, "Forbidden", "Access denied to this resource"),
116122
],
117123
)
118-
119124
class TestRaiseForStatusWithProblemDetails:
120125
def test_raises_http_problem_details_error(
121126
self, status_code: int, title: str, detail: str
@@ -146,7 +151,6 @@ def test_raises_http_problem_details_error(
146151
(403, "Client Error"),
147152
],
148153
)
149-
150154
class TestRaiseForStatusBackwardCompatibility:
151155
def test_raises_network_connection_error(
152156
self, status_code: int, error_type: str

0 commit comments

Comments
 (0)