Skip to content

Commit 5ad213a

Browse files
committed
Type annotations
1 parent 3d5bdc9 commit 5ad213a

File tree

5 files changed

+19
-30
lines changed

5 files changed

+19
-30
lines changed

cylc/flow/id.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,7 @@ def submit_num(self) -> int | None:
376376
>>> Tokens('//c/t').submit_num is None
377377
True
378378
"""
379-
if self['job'] is None:
380-
return None
381-
return int(self['job'])
379+
return int(self['job']) if self['job'] else None
382380

383381
@overload
384382
def duplicate(

cylc/flow/rundb.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,12 +715,11 @@ def select_task_action_timers(self, callback):
715715
callback(row_idx, list(row))
716716

717717
def select_task_job(
718-
self, cycle: str, name: str, submit_num: Union[str, int, None] = None
719-
) -> Optional[Dict[str, Any]]:
718+
self, cycle: str, name: str, submit_num: str | int | None = None
719+
) -> dict[str, Any] | None:
720720
"""Select items from task_jobs by (cycle, name, submit_num).
721721
722722
:return: a dict for mapping keys to the column values
723-
:rtype: dict
724723
"""
725724
keys = []
726725
for column in self.tables[self.TABLE_TASK_JOBS].columns[3:]:
@@ -739,7 +738,7 @@ def select_task_job(
739738
''' # nosec B608
740739
# * table name is code constant
741740
# * keys are code constants
742-
stmt_args: List[Any] = [cycle, name]
741+
stmt_args: list[Any] = [cycle, name]
743742
else:
744743
stmt = rf'''
745744
SELECT

cylc/flow/task_events_mgr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ def get_event_id(event: str, itask: 'TaskProxy') -> str:
221221
def log_task_job_activity(
222222
ctx: 'SubProcContext',
223223
workflow: str,
224-
point: Union[str, 'PointBase'],
224+
point: 'str | PointBase',
225225
name: str,
226-
submit_num: Union[str, int, None] = None,
226+
submit_num: str | int | None = None,
227227
):
228228
"""Log an activity for a task job."""
229229
ctx_str = str(ctx)
@@ -766,7 +766,7 @@ def process_message(
766766
if job_aborted:
767767
task_output = TASK_OUTPUT_FAILED
768768

769-
output_completed: Optional[bool] = False
769+
output_completed: bool | None = False
770770
if task_output not in {TASK_OUTPUT_SUBMIT_FAILED, TASK_OUTPUT_FAILED}:
771771
output_completed = (
772772
itask.state.outputs.set_message_complete(task_output, forced)
@@ -1372,7 +1372,7 @@ def _process_message_failed(
13721372
message: str,
13731373
forced: bool,
13741374
full_message: str,
1375-
run_signal: Optional[str] = None,
1375+
run_signal: str | None = None,
13761376
) -> bool:
13771377
"""Helper for process_message, handle a failed message.
13781378
@@ -1421,7 +1421,7 @@ def _process_job_failed(
14211421
self,
14221422
itask: 'TaskProxy',
14231423
event_time: str,
1424-
run_signal: Optional[str] = None,
1424+
run_signal: str | None = None,
14251425
):
14261426
itask.set_summary_time('finished', event_time)
14271427
self.data_store_mgr.delta_job_time(itask, 'finished', event_time)

cylc/flow/task_job_logs.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@
1616
"""Define job log filenames and option names."""
1717

1818
import os
19-
from typing import (
20-
TYPE_CHECKING,
21-
Optional,
22-
Union,
23-
)
19+
from typing import TYPE_CHECKING
2420

2521
from cylc.flow.id import Tokens
2622
from cylc.flow.pathutil import get_workflow_run_job_dir
@@ -52,10 +48,10 @@
5248

5349
def get_task_job_log(
5450
workflow: str,
55-
point: Union[str, 'PointBase'],
51+
point: 'str | PointBase',
5652
name: str,
57-
submit_num: Union[str, int, None] = None,
58-
suffix: Optional[str] = None,
53+
submit_num: str | int | None = None,
54+
suffix: str | None = None,
5955
):
6056
"""Return the full job log path."""
6157
args = [
@@ -73,9 +69,9 @@ def get_task_job_log(
7369

7470
def get_task_job_activity_log(
7571
workflow: str,
76-
point: Union[str, 'PointBase'],
72+
point: 'str | PointBase',
7773
name: str,
78-
submit_num: Union[str, int, None] = None,
74+
submit_num: str | int | None = None,
7975
):
8076
"""Shorthand for get_task_job_log(..., suffix="job-activity.log")."""
8177
return get_task_job_log(
@@ -85,9 +81,9 @@ def get_task_job_activity_log(
8581

8682
def get_task_job_job_log(
8783
workflow: str,
88-
point: Union[str, 'PointBase'],
84+
point: 'str | PointBase',
8985
name: str,
90-
submit_num: Union[str, int, None] = None,
86+
submit_num: str | int | None = None,
9187
):
9288
"""Shorthand for get_task_job_log(..., suffix="job")."""
9389
return get_task_job_log(workflow, point, name, submit_num, JOB_LOG_JOB)

cylc/flow/task_message.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@
2929
)
3030
import os
3131
import sys
32-
from typing import (
33-
List,
34-
Optional,
35-
Tuple,
36-
)
32+
from typing import List
3733

3834
from cylc.flow.exceptions import WorkflowStopped
3935
import cylc.flow.flags
@@ -82,7 +78,7 @@
8278
'''
8379

8480

85-
def split_run_signal(message: str) -> Tuple[str, Optional[str]]:
81+
def split_run_signal(message: str) -> tuple[str, str | None]:
8682
"""Get the run signal from a message.
8783
8884
>>> split_run_signal('failed/ERR')

0 commit comments

Comments
 (0)