Skip to content

Commit

Permalink
Fix type checking errors (#6016)
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie authored Mar 11, 2024
1 parent 5398941 commit aa100ef
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
3 changes: 2 additions & 1 deletion cylc/flow/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
Optional,
Set,
Union,
cast,
)

from cylc.flow import LOG
Expand Down Expand Up @@ -399,7 +400,7 @@ def remote_clean(
excp = PlatformError(
PlatformError.MSG_TIDY,
this_platform['name'],
cmd=item.proc.args,
cmd=cast('List[str]', item.proc.args),
ret_code=ret_code,
out=out,
err=err,
Expand Down
15 changes: 7 additions & 8 deletions cylc/flow/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from textwrap import wrap
from typing import (
Dict,
Iterable,
Optional,
Sequence,
Union,
TYPE_CHECKING,
)
Expand Down Expand Up @@ -184,7 +184,7 @@ def __init__(
platform_name: str,
*,
ctx: 'Optional[SubFuncContext]' = None,
cmd: Optional[Union[str, Iterable]] = None,
cmd: Union[str, Sequence[str], None] = None,
ret_code: Optional[int] = None,
out: Optional[str] = None,
err: Optional[str] = None
Expand Down Expand Up @@ -419,13 +419,12 @@ def get_hint(self):
)
):
# likely an issue with the ranking expression
ranking = "\n".join(
wrap(
self.data.get("ranking"),
initial_indent=' ',
subsequent_indent=' ',
)
lines = wrap(
self.data.get("ranking"),
initial_indent=' ',
subsequent_indent=' ',
)
ranking = "\n".join(lines)
return (
'This is likely an error in the ranking expression:'
f'\n{ranking}'
Expand Down
11 changes: 5 additions & 6 deletions cylc/flow/task_remote_mgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Set,
TYPE_CHECKING,
Tuple,
cast,
)

from cylc.flow import LOG
Expand Down Expand Up @@ -434,7 +435,7 @@ def remote_tidy(self) -> None:
PlatformError(
PlatformError.MSG_TIDY,
item.platform['name'],
cmd=item.proc.args,
cmd=cast('List[str]', item.proc.args),
ret_code=item.proc.returncode,
out=out,
err=err
Expand All @@ -451,7 +452,7 @@ def remote_tidy(self) -> None:
PlatformError(
PlatformError.MSG_TIDY,
item.platform['name'],
cmd=item.proc.args,
cmd=cast('List[str]', item.proc.args),
ret_code=item.proc.returncode,
out=out,
err=err,
Expand Down Expand Up @@ -508,10 +509,8 @@ def _remote_init_callback(
install_target=install_target
)
old_umask = os.umask(0o177)
with open(
public_key.full_key_path,
'w', encoding='utf8') as text_file:
text_file.write(key)
with open(public_key.full_key_path, 'w', encoding='utf8') as f:
f.write(key)
os.umask(old_umask)
# configure_curve must be called every time certificates are
# added or removed, in order to update the Authenticator's
Expand Down
5 changes: 2 additions & 3 deletions cylc/flow/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from typing import (
Any,
List,
Tuple,
Union,
Sequence,
)


Expand Down Expand Up @@ -77,7 +76,7 @@ def natural_sort(items: List[str], fcns=(int, str)) -> None:
items.sort(key=partial(natural_sort_key, fcns=fcns))


def format_cmd(cmd: Union[List[str], Tuple[str]], maxlen: int = 60) -> str:
def format_cmd(cmd: Sequence[str], maxlen: int = 60) -> str:
r"""Convert a shell command list to a user-friendly representation.
Examples:
Expand Down
18 changes: 12 additions & 6 deletions cylc/flow/workflow_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,21 @@ class KeyInfo(): # noqa: SIM119 (not really relevant here)
"""

def __init__(self, key_type, key_owner, full_key_path=None,
workflow_srv_dir=None, install_target=None, server_held=True):
def __init__(
self,
key_type: KeyType,
key_owner: KeyOwner,
full_key_path: Optional[str] = None,
workflow_srv_dir: Optional[str] = None,
install_target: Optional[str] = None,
server_held: bool = True
):
self.key_type = key_type
self.key_owner = key_owner
self.full_key_path = full_key_path
self.workflow_srv_dir = workflow_srv_dir
self.install_target = install_target
if self.full_key_path is not None:
self.key_path, self.file_name = os.path.split(self.full_key_path)
if full_key_path is not None:
self.key_path, self.file_name = os.path.split(full_key_path)
elif self.workflow_srv_dir is not None: # noqa: SIM106
# Build key filename
file_name = key_owner.value
Expand All @@ -129,7 +135,7 @@ def __init__(self, key_type, key_owner, full_key_path=None,
and self.install_target is not None):
file_name = f"{file_name}_{self.install_target}"

if key_type == KeyType.PRIVATE:
if key_type is KeyType.PRIVATE:
file_extension = WorkflowFiles.Service.PRIVATE_FILE_EXTENSION
else:
file_extension = WorkflowFiles.Service.PUBLIC_FILE_EXTENSION
Expand Down

0 comments on commit aa100ef

Please sign in to comment.