From 3facfaa52668a13d2b8d63ad23753838d955a70b Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 11 Jun 2022 10:17:20 -0500 Subject: [PATCH 1/3] chore: ConfigPath: Use type annotations for constructor --- src/tmuxp/cli/utils.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/tmuxp/cli/utils.py b/src/tmuxp/cli/utils.py index ba6cceccdec..ac41edbaebd 100644 --- a/src/tmuxp/cli/utils.py +++ b/src/tmuxp/cli/utils.py @@ -1,5 +1,6 @@ import logging import os +import typing as t import click from click.exceptions import FileError @@ -84,8 +85,30 @@ def func(value): class ConfigPath(click.Path): - def __init__(self, config_dir=None, *args, **kwargs): - super().__init__(*args, **kwargs) + def __init__( + self, + config_dir=None, + exists: bool = False, + file_okay: bool = True, + dir_okay: bool = True, + writable: bool = False, + readable: bool = True, + resolve_path: bool = False, + allow_dash: bool = False, + path_type: t.Optional[t.Type] = None, + executable: bool = False, + ): + super().__init__( + exists=exists, + file_okay=file_okay, + dir_okay=dir_okay, + writable=writable, + readable=readable, + resolve_path=resolve_path, + allow_dash=allow_dash, + path_type=path_type, + executable=executable, + ) self.config_dir = config_dir def convert(self, value, param, ctx): From f175a7bf7d49cc3966b7524458f674109c1babc4 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 11 Jun 2022 10:19:13 -0500 Subject: [PATCH 2/3] chore(cli): Annotate ConfigPath.convert --- src/tmuxp/cli/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/tmuxp/cli/utils.py b/src/tmuxp/cli/utils.py index ac41edbaebd..01a5b89324d 100644 --- a/src/tmuxp/cli/utils.py +++ b/src/tmuxp/cli/utils.py @@ -111,7 +111,12 @@ def __init__( ) self.config_dir = config_dir - def convert(self, value, param, ctx): + def convert( + self, + value: t.Any, + param: t.Optional[click.Parameter], + ctx: t.Optional[click.Context], + ) -> t.Any: config_dir = self.config_dir if callable(config_dir): config_dir = config_dir() From c18666b9fa81f8720c3ad55ff1055728dfe23a1f Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sat, 11 Jun 2022 10:23:02 -0500 Subject: [PATCH 3/3] chore(config_file_completion): Annotate --- src/tmuxp/cli/load.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tmuxp/cli/load.py b/src/tmuxp/cli/load.py index ee0ea232c35..ec4ac80385d 100644 --- a/src/tmuxp/cli/load.py +++ b/src/tmuxp/cli/load.py @@ -14,6 +14,7 @@ import click import kaptan +from click.shell_completion import CompletionItem from libtmux.common import has_gte_version from libtmux.server import Server @@ -441,7 +442,9 @@ def load_workspace( return _setup_plugins(builder) -def config_file_completion(ctx, params, incomplete): +def config_file_completion( + ctx: click.Context, param: click.Parameter, incomplete: str +) -> List[CompletionItem]: config_dir = pathlib.Path(get_config_dir()) choices: List[pathlib.Path] = []