From ad7c0210678a035dd8c1f9dd64d39b7ea6f5d18b Mon Sep 17 00:00:00 2001 From: MasterofJOKers Date: Tue, 25 Jan 2022 23:40:51 +0100 Subject: [PATCH] Add type hints for the functions --- sievedit.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sievedit.py b/sievedit.py index 54acaa5..5dc2f92 100644 --- a/sievedit.py +++ b/sievedit.py @@ -1,14 +1,15 @@ #!/usr/bin/env python3 import difflib import functools +from typing import Callable import click -from clintermission import cli_select_item -import editor -from sievelib.managesieve import Client +from clintermission import cli_select_item # type: ignore +import editor # type: ignore +from sievelib.managesieve import Client # type: ignore -def default_options(f): +def default_options(f: Callable) -> Callable: @click.option('--server', prompt=True, help='sieve server to connect to') @click.option('-u', '--user', prompt=True, help='user to connect as') @click.option('--password', prompt=True, hide_input=True, @@ -31,7 +32,7 @@ def main(): @default_options @click.option('--script-name', help='script name to set as active. If not provided, choices will be presented.') -def active(server, user, password, starttls, script_name): +def active(server: str, user: str, password: str, starttls: bool, script_name: str) -> int: """Connect to a SIEVE server and set a script as active""" c = Client(server) c.connect(user, password, starttls=starttls) @@ -45,7 +46,7 @@ def active(server, user, password, starttls, script_name): if active == script_name: click.echo('Script {} is already active.'.format(script_name)) - return + return 0 if script_name not in scripts: click.echo('Error: script {} cannot be found. Valid choices are: {}' @@ -53,6 +54,7 @@ def active(server, user, password, starttls, script_name): return 1 c.setactive(script_name) + return 0 DEFAULT_TEMPLATE = """\ @@ -83,7 +85,7 @@ if header :contains "To" "paypal@" { @main.command() @default_options @click.option('--script-name', help='Edit this script or create it') -def edit(server, user, password, starttls, script_name): +def edit(server: str, user: str, password: str, starttls: bool, script_name: str) -> None: """Connect to a SIEVE server, download, edit and upload a script""" c = Client(server) c.connect(user, password, starttls=starttls)