Skip to content

Commit dd5250d

Browse files
authored
chore: Update to Ruff 0.16 (#1514)
Co-authored-by: Dylan Anthony <dbanty@users.noreply.github.com>
1 parent 4d6baa7 commit dd5250d

30 files changed

Lines changed: 365 additions & 278 deletions

File tree

‎end_to_end_tests/functional_tests/helpers.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def inline_spec_should_fail(
9898
extra_args = []
9999
with generate_client_from_inline_spec(
100100
openapi_spec,
101-
extra_args,
102-
config,
101+
extra_args=extra_args,
102+
config=config,
103103
filename_suffix=filename_suffix,
104104
add_missing_sections=add_missing_sections,
105105
raise_on_error=False,

‎end_to_end_tests/generated_client.py‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def import_symbol(self, module_path: str, name: str) -> Any:
5959

6060
def _run_command(
6161
command: str,
62+
*,
6263
extra_args: list[str] | None = None,
6364
openapi_document: str | Path | None = None,
6465
url: str | None = None,
@@ -84,6 +85,7 @@ def _run_command(
8485

8586

8687
def generate_client(
88+
*,
8789
openapi_document: str | Path,
8890
extra_args: list[str] | None = None,
8991
output_path: str = "my-test-api-client",
@@ -102,7 +104,9 @@ def generate_client(
102104
args.extend(["--output-path", str(full_output_path)])
103105
if overwrite:
104106
args.append("--overwrite")
105-
generator_result = _run_command("generate", args, openapi_document, raise_on_error=raise_on_error)
107+
generator_result = _run_command(
108+
"generate", extra_args=args, openapi_document=openapi_document, raise_on_error=raise_on_error
109+
)
106110
return GeneratedClientContext(
107111
full_output_path,
108112
generator_result,
@@ -113,6 +117,7 @@ def generate_client(
113117

114118
def generate_client_from_inline_spec(
115119
openapi_spec: str,
120+
*,
116121
extra_args: list[str] | None = None,
117122
config: str = "",
118123
filename_suffix: str | None = None,
@@ -146,10 +151,10 @@ def generate_client_from_inline_spec(
146151
extra_args = [*extra_args, "--config", config_file.name]
147152

148153
generated_client = generate_client(
149-
file.name,
150-
extra_args,
151-
output_path,
152-
base_module,
154+
openapi_document=file.name,
155+
extra_args=extra_args,
156+
output_path=output_path,
157+
base_module=base_module,
153158
raise_on_error=raise_on_error,
154159
)
155160
os.unlink(file.name)

‎end_to_end_tests/golden-records/docstrings-on-attributes-golden-record/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from my_test_api_client import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

‎end_to_end_tests/golden-records/escapes-client/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from escapes_client import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

‎end_to_end_tests/golden-records/my-enum-api-client/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from my_enum_api_client import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

‎end_to_end_tests/golden-records/my-test-api-client/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from my_test_api_client import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

‎end_to_end_tests/golden-records/test-3-1-features-client/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from test_3_1_features_client import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

‎end_to_end_tests/test_end_to_end.py‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616

1717
def _compare_directories(
18+
*,
1819
record: Path,
1920
test_subject: Path,
2021
expected_differences: dict[Path, str] | None = None,
@@ -59,8 +60,8 @@ def _compare_directories(
5960

6061
for sub_path in dc.common_dirs:
6162
_compare_directories(
62-
record / sub_path,
63-
test_subject / sub_path,
63+
record=record / sub_path,
64+
test_subject=test_subject / sub_path,
6465
expected_differences=expected_differences,
6566
ignore=ignore,
6667
depth=depth + 1,
@@ -80,7 +81,7 @@ def run_e2e_test(
8081
*,
8182
golden_record_path: str | None = None,
8283
) -> Result:
83-
with generate_client(openapi_document, extra_args, output_path) as g:
84+
with generate_client(openapi_document=openapi_document, extra_args=extra_args, output_path=output_path) as g:
8485
if golden_record_path:
8586
gr_path = Path(__file__).parent / "golden-records" / golden_record_path
8687
else:
@@ -90,7 +91,10 @@ def run_e2e_test(
9091
# Use absolute paths for expected differences for easier comparisons
9192
expected_differences = {g.output_path.joinpath(key): value for key, value in expected_differences.items()}
9293
_compare_directories(
93-
gr_path, g.output_path, expected_differences=expected_differences, expected_missing=expected_missing
94+
record=gr_path,
95+
test_subject=g.output_path,
96+
expected_differences=expected_differences,
97+
expected_missing=expected_missing,
9498
)
9599

96100
result = subprocess.run(
@@ -146,7 +150,7 @@ def test_escapes_end_to_end():
146150
)
147151
def test_meta(meta: str, generated_file: str | None, expected_file: str | None):
148152
with generate_client(
149-
"3.1_specific.openapi.yaml",
153+
openapi_document="3.1_specific.openapi.yaml",
150154
extra_args=[f"--meta={meta}"],
151155
output_path="test-3-1-features-client",
152156
) as g:
@@ -220,7 +224,7 @@ def test_bad_url():
220224
@pytest.mark.parametrize("document", ERROR_DOCUMENTS, ids=[path.stem for path in ERROR_DOCUMENTS])
221225
def test_documents_with_errors(snapshot, document):
222226
with generate_client(
223-
document,
227+
openapi_document=document,
224228
extra_args=["--fail-on-warning"],
225229
output_path="test-documents-with-errors",
226230
raise_on_error=False,
@@ -234,8 +238,8 @@ def test_documents_with_errors(snapshot, document):
234238
def test_custom_post_hooks():
235239
config_path = Path(__file__).parent / "custom_post_hooks.config.yml"
236240
with generate_client(
237-
"baseline_openapi_3.0.json",
238-
[f"--config={config_path}"],
241+
openapi_document="baseline_openapi_3.0.json",
242+
extra_args=[f"--config={config_path}"],
239243
raise_on_error=False,
240244
) as g:
241245
assert g.generator_result.exit_code == 1
@@ -271,7 +275,7 @@ def test_update_integration_tests():
271275
url=url,
272276
config_path=config_path,
273277
)
274-
_compare_directories(source_path, temp_dir, ignore=["pyproject.toml"])
278+
_compare_directories(record=source_path, test_subject=temp_dir, ignore=["pyproject.toml"])
275279
result = subprocess.run(
276280
[sys.executable, "-m", "mypy", str(temp_dir), "--strict"],
277281
capture_output=True,

‎fuzz/test_codegen.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ def test_valid_openapi_never_generates_invalid_python(document: dict[str, Any],
288288
document_path.write_text(json.dumps(document, ensure_ascii=False), encoding="utf-8")
289289

290290
config = Config.from_sources(
291-
ConfigFile(
291+
config_file=ConfigFile(
292292
project_name_override="fuzz-client",
293293
package_name_override="fuzz_client",
294294
post_hooks=[],
295295
),
296-
meta_type,
296+
meta_type=meta_type,
297297
document_source=document_path,
298298
file_encoding="utf-8",
299299
overwrite=False,

‎integration-tests/README.md‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ client = AuthenticatedClient(
5656
You can also disable certificate validation altogether, but beware that **this is a security risk**.
5757

5858
```python
59-
client = AuthenticatedClient(
60-
base_url="https://internal_api.example.com",
61-
token="SuperSecretToken",
62-
verify_ssl=False
63-
)
59+
client = AuthenticatedClient(base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False)
6460
```
6561

6662
Things to know:
@@ -81,13 +77,16 @@ There are more settings on the generated `Client` class which let you control mo
8177
```python
8278
from integration_tests import Client
8379

80+
8481
def log_request(request):
8582
print(f"Request event hook: {request.method} {request.url} - Waiting for response")
8683

84+
8785
def log_response(response):
8886
request = response.request
8987
print(f"Response event hook: {request.method} {request.url} - Status {response.status_code}")
9088

89+
9190
client = Client(
9291
base_url="https://api.example.com",
9392
httpx_args={"event_hooks": {"request": [log_request], "response": [log_response]}},

0 commit comments

Comments
 (0)