From 3fa367602ffa6eae385203fe9339e86fa02655ba Mon Sep 17 00:00:00 2001 From: Elia El Lazkani Date: Mon, 4 Nov 2019 18:02:42 +0100 Subject: [PATCH] Fixing typing for the NoReturn type methods --- shortenit/data.py | 11 ++++++----- shortenit/db.py | 7 ++++--- shortenit/logger.py | 3 ++- shortenit/main.py | 5 +++-- shortenit/pointer.py | 3 ++- shortenit/shortener.py | 5 +++-- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/shortenit/data.py b/shortenit/data.py index c1e4a7a..fb61614 100644 --- a/shortenit/data.py +++ b/shortenit/data.py @@ -1,3 +1,4 @@ +import typing import time import logging @@ -11,7 +12,7 @@ class Data: """ def __init__(self, data_db: object, identifier: str = None, - data: str = None) -> None: + data: str = None) -> typing.NoReturn: """ Initialize the Data object. @@ -28,14 +29,14 @@ class Data: self.data_found = None self.populate() - def generate_identifier(self) -> None: + def generate_identifier(self) -> typing.NoReturn: """ Method to generate and save a new unique ID as the Data object identifier. """ hash_object = sha256(self.data.encode('utf-8')) self.identifier = hash_object.hexdigest() - def populate(self, pointer: str = None) -> None: + def populate(self, pointer: str = None) -> typing.NoReturn: """ Method to populate the Data object fields with proper data and save it in the database. @@ -55,7 +56,7 @@ class Data: "creating...") self.set_data(pointer) - def get_data(self) -> None: + def get_data(self) -> typing.NoReturn: """ Method to retrieve the Data ojbect from the database. """ @@ -68,7 +69,7 @@ class Data: except KeyError: self.data_found = False - def set_data(self, pointer: str) -> None: + def set_data(self, pointer: str) -> typing.NoReturn: """ Method to save Data object to the database. """ diff --git a/shortenit/db.py b/shortenit/db.py index d489907..640fc7f 100644 --- a/shortenit/db.py +++ b/shortenit/db.py @@ -1,3 +1,4 @@ +import typing import logging import requests @@ -9,7 +10,7 @@ class DB: """ Database object class """ - def __init__(self, config: dict) -> None: + def __init__(self, config: dict) -> typing.NoReturn: """ Initialize the Database object. @@ -22,7 +23,7 @@ class DB: self.client = None self.session = None - def initialize_shortenit(self) -> None: + def initialize_shortenit(self) -> typing.NoReturn: """ Method to initialize the database for shortenit. This will check if all the needed tables already exist in the database. @@ -68,7 +69,7 @@ class DB: self.session = self.client.session() return self - def __exit__(self, *args) -> None: + def __exit__(self, *args) -> typing.NoReturn: """ Method used when exiting the database context. """ diff --git a/shortenit/logger.py b/shortenit/logger.py index f0e2a0f..3639557 100644 --- a/shortenit/logger.py +++ b/shortenit/logger.py @@ -1,4 +1,5 @@ import os +import typing import yaml import logging.config from .common import check_file @@ -6,7 +7,7 @@ from .common import check_file def setup_logging(default_path: str = None, default_level: int = logging.ERROR, - env_key: str = 'LOG_CFG') -> None: + env_key: str = 'LOG_CFG') -> typing.NoReturn: """ Method that sets the logging system up. diff --git a/shortenit/main.py b/shortenit/main.py index 4289a6f..28d7a63 100644 --- a/shortenit/main.py +++ b/shortenit/main.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import sys +import typing import argparse import logging import pathlib @@ -23,7 +24,7 @@ CONFIGURATION = f'{PROJECT_ROOT}/config/config.yaml' logger = logging.getLogger(__name__) -def main() -> None: +def main() -> typing.NoReturn: """ Main method """ @@ -111,4 +112,4 @@ def verbosity(verbose: int): if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/shortenit/pointer.py b/shortenit/pointer.py index eba6d41..cecaee4 100644 --- a/shortenit/pointer.py +++ b/shortenit/pointer.py @@ -1,6 +1,7 @@ from __future__ import annotations import time +import typing import logging from cloudant.document import Document @@ -11,7 +12,7 @@ class Pointer: Pointer object. """ def __init__(self, pointers_db: object, - identifier: str = None) -> None: + identifier: str = None) -> typing.NoReturn: """ Initialize the Pointer object. diff --git a/shortenit/shortener.py b/shortenit/shortener.py index 753e8ff..6e4f1b5 100644 --- a/shortenit/shortener.py +++ b/shortenit/shortener.py @@ -1,4 +1,5 @@ import uuid +import typing import logging from cloudant.document import Document @@ -8,7 +9,7 @@ class Shortener: """ Shortener object """ - def __init__(self, pointer_db, configuration: dict) -> None: + def __init__(self, pointer_db, configuration: dict) -> typing.NoReturn: """ Initialize the Shortener object. @@ -24,7 +25,7 @@ class Shortener: self.configuration = configuration self.init() - def init(self) -> None: + def init(self) -> typing.NoReturn: """ Initialize the shortener from the configuration. """