From 3e1dea34efd1b2620b3b2e4a7bae7ec49480fede Mon Sep 17 00:00:00 2001 From: Jeel Dobariya Date: Tue, 7 Nov 2023 16:47:37 +0530 Subject: [PATCH] add typehint --- src/app/commands.py | 11 ++++++----- src/app/datahandler.py | 8 +++++--- src/app/eventhandler.py | 10 +++++----- src/app/metadata.py | 18 +++++++++--------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/app/commands.py b/src/app/commands.py index 8997e20..cd2b5b7 100644 --- a/src/app/commands.py +++ b/src/app/commands.py @@ -1,32 +1,33 @@ from . import datahandler from . import metadata -def quit_appplication(): +def quit_appplication() -> None: print("Quiting the Application....") -def print_help_message(): +def print_help_message() -> None: print("Here are valid commands:") print(" - \"quit\" or \"exit\": for quiting the app") print(" - \"read\" or \"load\": for reading or loading the existing passwords") print(" - \"write\" or \"save\": for writing or saveing the new passwords") print() -def write_password(): +def write_password() -> None: website = input("Enter a website: ") password = input("Enter a password: ") datahandler.save_data(website, password) print("operation successfull!!!") print() -def read_password(): +def read_password() -> None: data_list = datahandler.load_data() try: for data_item in data_list: print(f"{data_item[0]} - {data_item[1]}") + print() except IndexError as _: raise Exception("data is corrupted!!") -def read_info(): +def read_info() -> None: path = metadata.RESOURCEDIR_PATH + "info.txt" with open(path) as f: data = f.read() diff --git a/src/app/datahandler.py b/src/app/datahandler.py index 1521f2a..3a7f4fb 100644 --- a/src/app/datahandler.py +++ b/src/app/datahandler.py @@ -1,13 +1,15 @@ from . import metadata -DATA_FILE = metadata.DATADIR_PATH + "data.txt" +from typing import List -def save_data(website, password): +DATA_FILE: str = metadata.DATADIR_PATH + "data.txt" + +def save_data(website: str, password: str) -> None: data = metadata.DATA_SEPARATOR.join([website, password]) with open(DATA_FILE, "a") as f: f.write(data + '\n') -def load_data(): +def load_data() -> List[str]: data_list = [] with open(DATA_FILE) as f: data = f.read() diff --git a/src/app/eventhandler.py b/src/app/eventhandler.py index f6bf96f..b1a340c 100644 --- a/src/app/eventhandler.py +++ b/src/app/eventhandler.py @@ -1,16 +1,16 @@ from . import commands -def handle_quit_event(): +def handle_quit_event() -> None: commands.quit_appplication() -def handle_help_event(): +def handle_help_event() -> None: commands.print_help_message() -def handle_write_password_event(): +def handle_write_password_event() -> None: commands.write_password() -def handle_read_password_event(): +def handle_read_password_event() -> None: commands.read_password() -def handle_info_event(): +def handle_info_event() -> None: commands.read_info() diff --git a/src/app/metadata.py b/src/app/metadata.py index 1f4d33b..027d238 100644 --- a/src/app/metadata.py +++ b/src/app/metadata.py @@ -3,18 +3,18 @@ import os # App -NAME = "Smart Manager" -VERSION = "0.1.0-alpha" -WEBSITE = "https://jeeldobariya38.github.io/Smart-Manager/" -REPO = "https://github.com/JeelDobariya38/Smart-Manager" +NAME: str = "Smart Manager" +VERSION: str = "0.1.0-alpha" +WEBSITE: str = "https://jeeldobariya38.github.io/Smart-Manager/" +REPO: str = "https://github.com/JeelDobariya38/Smart-Manager" # Paths (all path are relative to this file) -__DATADIR = ["..", "..", "..", "data"] -__RESOURCEDIR = ["..", "..", "..", "resource"] +__DATADIR: str = ["..", "..", "..", "data"] +__RESOURCEDIR: str = ["..", "..", "..", "resource"] # FilePath (Do Not Change this session, instead change above "Paths" session) -DATADIR_PATH = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep -RESOURCEDIR_PATH = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep +DATADIR_PATH: str = os.path.join(__file__, os.path.sep.join(__DATADIR)) + os.path.sep +RESOURCEDIR_PATH: str = os.path.join(__file__, os.path.sep.join(__RESOURCEDIR)) + os.path.sep # App Configuration -DATA_SEPARATOR = " -> " +DATA_SEPARATOR: str = " -> "