Skip to content

Commit 92cab10

Browse files
authored
Bump ruff to 0.15 and reformat (#1507)
* Bump ruff to 0.15 and reformat Also bump `[tool.ruff] target-version` from py39 to py310 to match `requires-python`; the old setting caused 0.15 to reject `match` statements in the codebase. * Restrict lockfile changes to ruff only
1 parent c9e2873 commit 92cab10

26 files changed

Lines changed: 299 additions & 297 deletions

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dev = [
6464
"pytest~=9.0",
6565
"pytest-asyncio>=0.21,<0.22",
6666
"pytest-timeout~=2.2",
67-
"ruff>=0.5.0,<0.6",
67+
"ruff>=0.15.12,<0.16",
6868
"toml>=0.10.2,<0.11",
6969
"twine>=4.0.1,<5",
7070
"maturin>=1.8.2",
@@ -239,7 +239,7 @@ exclude = [
239239
]
240240

241241
[tool.ruff]
242-
target-version = "py39"
242+
target-version = "py310"
243243

244244
[build-system]
245245
requires = ["maturin>=1.0,<2.0"]

scripts/gen_bridge_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def generate_python_services(
4242
''')
4343

4444
def service_name(s):
45-
return f"import {sanitize_proto_name(s.full_name)[:-len(s.name)-1]}"
45+
return f"import {sanitize_proto_name(s.full_name)[: -len(s.name) - 1]}"
4646

4747
service_imports = [
4848
service_name(service_descriptor)

scripts/gen_protos.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ def check_proto_toolchain_versions():
153153
_, _, proto_version = line.partition("==")
154154
elif line.startswith("grpcio-tools"):
155155
_, _, grpcio_tools_version = line.partition("==")
156-
assert proto_version.startswith(
157-
"3."
158-
), f"expected 3.x protobuf, found {proto_version}"
159-
assert grpcio_tools_version.startswith(
160-
"1.48."
161-
), f"expected 1.48.x grpcio-tools, found {grpcio_tools_version}"
156+
assert proto_version.startswith("3."), (
157+
f"expected 3.x protobuf, found {proto_version}"
158+
)
159+
assert grpcio_tools_version.startswith("1.48."), (
160+
f"expected 1.48.x grpcio-tools, found {grpcio_tools_version}"
161+
)
162162

163163

164164
def generate_protos(output_dir: Path):

temporalio/worker/workflow_sandbox/_importer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ def _calc___package__(globals: Mapping[str, object]) -> str:
558558
if package is not None:
559559
if spec is not None and package != spec.parent:
560560
warnings.warn(
561-
"__package__ != __spec__.parent " f"({package!r} != {spec.parent!r})",
561+
f"__package__ != __spec__.parent ({package!r} != {spec.parent!r})",
562562
DeprecationWarning,
563563
stacklevel=3,
564564
)

tests/conftest.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
# If there is an integration test environment variable set, we must remove the
2020
# first path from the sys.path so we can import the wheel instead
2121
if os.getenv("TEMPORAL_INTEGRATION_TEST"):
22-
assert (
23-
sys.path[0] == os.getcwd()
24-
), "Expected first sys.path to be the current working dir"
22+
assert sys.path[0] == os.getcwd(), (
23+
"Expected first sys.path to be the current working dir"
24+
)
2525
sys.path.pop(0)
2626
# Import temporalio and confirm it is prefixed with virtual env
2727
import temporalio
2828

29-
assert temporalio.__file__.startswith(
30-
sys.prefix
31-
), f"Expected {temporalio.__file__} to be in {sys.prefix}"
29+
assert temporalio.__file__.startswith(sys.prefix), (
30+
f"Expected {temporalio.__file__} to be in {sys.prefix}"
31+
)
3232

3333
# Unless specifically overridden, we expect tests to run under protobuf 4.x/5.x lib
3434
import google.protobuf
3535

3636
protobuf_version = google.protobuf.__version__
3737
if os.getenv("TEMPORAL_TEST_PROTO3"):
38-
assert protobuf_version.startswith(
39-
"3."
40-
), f"Expected protobuf 3.x, got {protobuf_version}"
38+
assert protobuf_version.startswith("3."), (
39+
f"Expected protobuf 3.x, got {protobuf_version}"
40+
)
4141
else:
4242
assert (
4343
protobuf_version.startswith("4.")

tests/contrib/aws/lambda_worker/test_lambda_worker.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,13 @@ def fake_create_worker(_client: Any, **kwargs: Any) -> Any:
247247
load_config=lambda: ClientConfigProfile(),
248248
getenv={"TEMPORAL_TASK_QUEUE": "test-queue"}.get, # type: ignore[arg-type]
249249
extract_lambda_ctx=lambda ctx: (
250-
ctx.aws_request_id,
251-
ctx.invoked_function_arn,
252-
)
253-
if hasattr(ctx, "aws_request_id")
254-
else None,
250+
(
251+
ctx.aws_request_id,
252+
ctx.invoked_function_arn,
253+
)
254+
if hasattr(ctx, "aws_request_id")
255+
else None
256+
),
255257
)
256258

257259

tests/contrib/aws/s3driver/test_s3driver.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ async def test_skips_upload_when_key_exists(
430430
assert counting_driver_client.put_object_count == 1
431431

432432
await driver.store(make_store_context(), [payload])
433-
assert (
434-
counting_driver_client.put_object_count == 1
435-
), "put_object should not be called for an existing key"
433+
assert counting_driver_client.put_object_count == 1, (
434+
"put_object should not be called for an existing key"
435+
)
436436

437437
async def test_skips_upload_preserves_data(
438438
self, driver_client: S3StorageDriverClient
@@ -812,9 +812,9 @@ async def test_store_cancels_remaining_on_failure(
812812

813813
assert isinstance(exc_info.value.__cause__, ConnectionError)
814814
assert str(exc_info.value.__cause__) == "S3 connection lost"
815-
assert (
816-
len(faulty_client.cancelled) == 2
817-
), "Expected 2 remaining tasks to be cancelled"
815+
assert len(faulty_client.cancelled) == 2, (
816+
"Expected 2 remaining tasks to be cancelled"
817+
)
818818

819819
async def test_retrieve_cancels_remaining_on_failure(
820820
self, driver_client: S3StorageDriverClient
@@ -838,9 +838,9 @@ async def test_retrieve_cancels_remaining_on_failure(
838838

839839
assert isinstance(exc_info.value.__cause__, ConnectionError)
840840
assert str(exc_info.value.__cause__) == "S3 connection lost"
841-
assert (
842-
len(faulty_client.cancelled) == 2
843-
), "Expected 2 remaining tasks to be cancelled"
841+
assert len(faulty_client.cancelled) == 2, (
842+
"Expected 2 remaining tasks to be cancelled"
843+
)
844844

845845

846846
# ---------------------------------------------------------------------------

tests/contrib/langgraph/test_continue_as_new_cached.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ async def test_graph_continue_as_new_cached(client: Client):
120120
assert result == {"value": 260}
121121

122122
# Each node should execute exactly once — phases 2 and 3 use cached results.
123-
assert (
124-
_execution_counts.get("multiply", 0) == 1
125-
), f"multiply executed {_execution_counts.get('multiply', 0)} times, expected 1"
126-
assert (
127-
_execution_counts.get("add", 0) == 1
128-
), f"add executed {_execution_counts.get('add', 0)} times, expected 1"
129-
assert (
130-
_execution_counts.get("double", 0) == 1
131-
), f"double executed {_execution_counts.get('double', 0)} times, expected 1"
123+
assert _execution_counts.get("multiply", 0) == 1, (
124+
f"multiply executed {_execution_counts.get('multiply', 0)} times, expected 1"
125+
)
126+
assert _execution_counts.get("add", 0) == 1, (
127+
f"add executed {_execution_counts.get('add', 0)} times, expected 1"
128+
)
129+
assert _execution_counts.get("double", 0) == 1, (
130+
f"double executed {_execution_counts.get('double', 0)} times, expected 1"
131+
)

tests/contrib/langgraph/test_e2e_functional.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ async def test_continue_as_new_with_checkpoint(self, client: Client) -> None:
219219
assert result["result"] == 260
220220

221221
counts = get_task_execution_counts()
222-
assert (
223-
counts.get("task_a", 0) == 1
224-
), f"task_a executed {counts.get('task_a', 0)} times, expected 1"
225-
assert (
226-
counts.get("task_b", 0) == 1
227-
), f"task_b executed {counts.get('task_b', 0)} times, expected 1"
228-
assert (
229-
counts.get("task_c", 0) == 1
230-
), f"task_c executed {counts.get('task_c', 0)} times, expected 1"
222+
assert counts.get("task_a", 0) == 1, (
223+
f"task_a executed {counts.get('task_a', 0)} times, expected 1"
224+
)
225+
assert counts.get("task_b", 0) == 1, (
226+
f"task_b executed {counts.get('task_b', 0)} times, expected 1"
227+
)
228+
assert counts.get("task_c", 0) == 1, (
229+
f"task_c executed {counts.get('task_c', 0)} times, expected 1"
230+
)
231231

232232

233233
class TestFunctionalAPIPartialExecution:
@@ -266,9 +266,9 @@ async def test_partial_execution_five_tasks(self, client: Client) -> None:
266266

267267
counts = get_task_execution_counts()
268268
for i in range(1, 6):
269-
assert (
270-
counts.get(f"step_{i}", 0) == 1
271-
), f"step_{i} executed {counts.get(f'step_{i}', 0)} times, expected 1"
269+
assert counts.get(f"step_{i}", 0) == 1, (
270+
f"step_{i} executed {counts.get(f'step_{i}', 0)} times, expected 1"
271+
)
272272

273273

274274
class TestFunctionalAPIInterruptV2:

tests/contrib/langsmith/test_integration.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -367,27 +367,27 @@ async def test_workflow_activity_trace_hierarchy(
367367
" RunActivity:simple_activity",
368368
" simple_activity",
369369
]
370-
assert (
371-
hierarchy == expected
372-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
370+
assert hierarchy == expected, (
371+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
372+
)
373373

374374
# Verify run_type: RunActivity is "tool", others are "chain"
375375
for run in collector.runs:
376376
if run.name == "RunActivity:simple_activity":
377-
assert (
378-
run.run_type == "tool"
379-
), f"Expected RunActivity run_type='tool', got '{run.run_type}'"
377+
assert run.run_type == "tool", (
378+
f"Expected RunActivity run_type='tool', got '{run.run_type}'"
379+
)
380380
else:
381-
assert (
382-
run.run_type == "chain"
383-
), f"Expected {run.name} run_type='chain', got '{run.run_type}'"
381+
assert run.run_type == "chain", (
382+
f"Expected {run.name} run_type='chain', got '{run.run_type}'"
383+
)
384384

385385
# Verify successful runs have outputs == {"status": "ok"}
386386
for run in collector.runs:
387387
if ":" in run.name: # Interceptor runs use "Type:Name" format
388-
assert run.outputs == {
389-
"status": "ok"
390-
}, f"Expected {run.name} outputs={{'status': 'ok'}}, got {run.outputs}"
388+
assert run.outputs == {"status": "ok"}, (
389+
f"Expected {run.name} outputs={{'status': 'ok'}}, got {run.outputs}"
390+
)
391391

392392

393393
# ---------------------------------------------------------------------------
@@ -475,9 +475,9 @@ async def test_activity_failure_marked(
475475
" RunActivity:failing_activity",
476476
" failing_activity",
477477
]
478-
assert (
479-
hierarchy == expected
480-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
478+
assert hierarchy == expected, (
479+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
480+
)
481481
# Verify the RunActivity run has an error
482482
activity_runs = [
483483
r for r in collector.runs if r.name == "RunActivity:failing_activity"
@@ -514,9 +514,9 @@ async def test_workflow_failure_marked(
514514
"StartWorkflow:FailingWorkflow",
515515
"RunWorkflow:FailingWorkflow",
516516
]
517-
assert (
518-
hierarchy == expected
519-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
517+
assert hierarchy == expected, (
518+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
519+
)
520520
# Verify the RunWorkflow run has an error
521521
wf_runs = [r for r in collector.runs if r.name == "RunWorkflow:FailingWorkflow"]
522522
assert len(wf_runs) == 1
@@ -555,9 +555,9 @@ async def test_benign_error_not_marked(
555555
" RunActivity:benign_failing_activity",
556556
" benign_failing_activity",
557557
]
558-
assert (
559-
hierarchy == expected
560-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
558+
assert hierarchy == expected, (
559+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
560+
)
561561
# The RunActivity run for benign error should NOT have error set
562562
activity_runs = [
563563
r for r in collector.runs if r.name == "RunActivity:benign_failing_activity"
@@ -988,15 +988,15 @@ async def test_factory_traceable_no_external_context(
988988
" outer_chain",
989989
" inner_llm_call",
990990
]
991-
assert (
992-
hierarchy == expected
993-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
991+
assert hierarchy == expected, (
992+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
993+
)
994994

995995
# Verify no duplicate run IDs (replay safety with max_cached_workflows=0)
996996
run_ids = [r.id for r in collector.runs]
997-
assert len(run_ids) == len(
998-
set(run_ids)
999-
), f"Duplicate run IDs found (replay issue): {run_ids}"
997+
assert len(run_ids) == len(set(run_ids)), (
998+
f"Duplicate run IDs found (replay issue): {run_ids}"
999+
)
10001000

10011001
async def test_factory_passes_project_name_to_children(
10021002
self,
@@ -1081,15 +1081,15 @@ async def test_mixed_sync_async_traceable_with_temporal_runs(
10811081
" outer_chain",
10821082
" inner_llm_call",
10831083
]
1084-
assert (
1085-
hierarchy == expected
1086-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
1084+
assert hierarchy == expected, (
1085+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
1086+
)
10871087

10881088
# Verify no duplicate run IDs (replay safety with max_cached_workflows=0)
10891089
run_ids = [r.id for r in collector.runs]
1090-
assert len(run_ids) == len(
1091-
set(run_ids)
1092-
), f"Duplicate run IDs found (replay issue): {run_ids}"
1090+
assert len(run_ids) == len(set(run_ids)), (
1091+
f"Duplicate run IDs found (replay issue): {run_ids}"
1092+
)
10931093

10941094

10951095
# --- Nexus service with direct @traceable call in handler ---
@@ -1190,9 +1190,9 @@ async def test_nexus_direct_traceable_without_temporal_runs(
11901190
"nexus_direct_traceable",
11911191
" inner_llm_call",
11921192
]
1193-
assert (
1194-
hierarchy == expected
1195-
), f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
1193+
assert hierarchy == expected, (
1194+
f"Hierarchy mismatch.\nExpected:\n{expected}\nActual:\n{hierarchy}"
1195+
)
11961196

11971197

11981198
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)