From 313ec87258f7899de7a0c08dbef0bdf1a1c3c86b Mon Sep 17 00:00:00 2001 From: Moul <moul@moul.re> Date: Sun, 5 Jun 2022 16:42:36 +0200 Subject: [PATCH] [mypy] #163: Add type annotation on checksum, cli, and cli_tools --- silkaj/checksum.py | 2 +- silkaj/cli.py | 30 +++++++++++++++--------------- silkaj/cli_tools.py | 8 +++++--- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/silkaj/checksum.py b/silkaj/checksum.py index d095e598..a7bfaa37 100644 --- a/silkaj/checksum.py +++ b/silkaj/checksum.py @@ -35,7 +35,7 @@ MESSAGE = "You should specify a pubkey or an authentication method" Can also check if the checksum is valid", ) @click.argument("pubkey_checksum", nargs=-1) -def checksum_command(pubkey_checksum): +def checksum_command(pubkey_checksum: str) -> None: if has_auth_method(): key = auth_method() click.echo(gen_pubkey_checksum(key.pubkey)) diff --git a/silkaj/cli.py b/silkaj/cli.py index 1930bbd9..d8203875 100644 --- a/silkaj/cli.py +++ b/silkaj/cli.py @@ -15,7 +15,7 @@ import sys -from click import group, help_option, option, pass_context, version_option +from click import Context, group, help_option, option, pass_context, version_option from duniterpy.api.endpoint import endpoint from silkaj import revocation @@ -91,18 +91,18 @@ Do not send the document, but display it instead", ) @pass_context def cli( - ctx, - endpoint, - gtest, - auth_scrypt, - nrp, - auth_file, - file, - auth_seed, - auth_wif, - display, - dry_run, -): + ctx: Context, + endpoint: str, + gtest: bool, + auth_scrypt: bool, + nrp: str, + auth_file: bool, + file: str, + auth_seed: bool, + auth_wif: bool, + display: bool, + dry_run: bool, +) -> None: if display and dry_run: sys.exit("ERROR: display and dry-run options can not be used together") @@ -143,7 +143,7 @@ cli.add_command(received_sent_certifications) Subcommands optionally take the path to the revocation document.", ) @help_option("-h", "--help") -def revocation_group(): +def revocation_group() -> None: pass @@ -154,7 +154,7 @@ revocation_group.add_command(revocation.revoke_now) @cli.command("about", help="Display program information") -def about(): +def about() -> None: print( "\ \n @@@@@@@@@@@@@\ diff --git a/silkaj/cli_tools.py b/silkaj/cli_tools.py index 9928d230..498a110a 100644 --- a/silkaj/cli_tools.py +++ b/silkaj/cli_tools.py @@ -13,11 +13,13 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -from click import Option, UsageError +from typing import Any + +from click import Context, Option, UsageError class MutuallyExclusiveOption(Option): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any) -> None: self.mutually_exclusive = set(kwargs.pop("mutually_exclusive", [])) help = kwargs.get("help", "") if self.mutually_exclusive: @@ -27,7 +29,7 @@ class MutuallyExclusiveOption(Option): ] = f"{help} NOTE: This argument is mutually exclusive with arguments: [{ex_str}]." super().__init__(*args, **kwargs) - def handle_parse_result(self, ctx, opts, args): + def handle_parse_result(self, ctx: Context, opts: Any, args: Any) -> Any: if self.mutually_exclusive.intersection(opts) and self.name in opts: arguments = ", ".join(self.mutually_exclusive) raise UsageError( -- GitLab