Fixing typing for the NoReturn type methods

This commit is contained in:
Elia El Lazkani 2019-11-04 18:02:42 +01:00
parent e9d2b2b23e
commit 3fa367602f
6 changed files with 20 additions and 14 deletions

View file

@ -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.
"""

View file

@ -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.
"""

View file

@ -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.

View file

@ -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
"""

View file

@ -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.

View file

@ -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.
"""