From e64c6d7f41745e507b2c85e2ee9faf77d2dc433c Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Thu, 9 Jun 2022 15:21:46 +0200 Subject: [PATCH] error_mngr.py : rtype and function doc (part) --- src/bootstraparse/modules/error_mngr.py | 57 +++++++++++++++++++------ 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/src/bootstraparse/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py index 83eed01..0e95ae7 100644 --- a/src/bootstraparse/modules/error_mngr.py +++ b/src/bootstraparse/modules/error_mngr.py @@ -21,11 +21,14 @@ __all__ = _ERRORS+[] def init_logging(filename=None, loglevel="ERROR", filemode='w', handler=None): """ Initializes logging - :param filename: The name of the log file - :param loglevel: The level of logging - :type loglevel: str - :param filemode: The mode of the log file + :param filename: The path for the log file + :param loglevel: The level of logging: "ERROR", "INFO", "WARNING", "DEBUG", "CRITICAL" + :param filemode: The mode of the log file: "w", "a" :param handler: The handler to use + :type filename: str + :type loglevel: str + :type filemode: str + :type handler: logging.Handler :return: None """ loglevel = loglevel.upper() @@ -50,6 +53,7 @@ def log_message(message, level="ERROR"): :param message: The message to log :param level: The level of the message :type level: str + :type message: str :return: None """ level = level.lower() @@ -85,9 +89,11 @@ def log_exception(exception, level="ERROR"): def dict_check(dic, *args): """ - Helper function to test existence within a dictionary. + Helper function to test existence of a list of succesive keys within a nested dictionary. :param dic: The dictionary of dictionaries to check :param args: Any number of keys to check the dictionaries for + :type dic: dict | config.ConfigLoader + :type args: str :return: A table of Booleans for every key checked. """ output = [False for _ in args] @@ -102,33 +108,45 @@ def dict_check(dic, *args): def str_dict_check(dic, *args): """ - Helper function to test existence within a dictionary and return a string of the values. + Helper function to test existence within a dictionary and return a string of the values of the keys checked + and wether they exist. 'arg[0]' : True or False - + :param dic: The nested dictionary to check + :param args: Any number of keys to check successively + :type dic: dict + :type args: str + :return: A string of the values of the keys checked and wether they exist. + :rtype: str """ out = dict_check(dic, *args) return "\n".join([f"{args[i]}: {out[i]}" for i in range(len(out))]) class BootstraparseError(Exception): + """ + Base class for all Bootstraparse errors + """ pass class ParsingError(Exception): """ Exception class for parsing errors - :param message: The message to display - :type message: str - :param line: The line number of the error - :param column: The column number of the error - :param file: The name of the file - :return: None """ def __init__(self, message=None, line=None, column=None, file=None): """ Initializes the ParsingError class with the filename and a line and column number based on the current position in the file (if available) + :param message: The message to display + :type message: str + :param line: The line number of the error + :type line: int + :param column: The column number of the error + :type column: int + :param file: The name of the file + :type file: str + :return: None """ super().__init__(message) self.line = line @@ -154,6 +172,11 @@ class MismatchedContainerError(BootstraparseError): The token is not final and cannot be contained. Indicative of a mismatched token. """ def __init__(self, token): + """ + Initializes the MismatchedContainerError class with the token that was not final + :param token: The token that is not final + :type token: syntax.SemanticType + """ self.token = token if token: self.line = token.line_number @@ -171,6 +194,14 @@ class LonelyOptionalError(BootstraparseError): Optional token could not be matched with last element in pile (not a container). """ def __init__(self, token, last_in_pile): + """ + Initializes the LonelyOptionalError class with the token found and the last element in the pile + Used when a token is found that is optional and cannot be matched with the last element in the pile (not a container) + :param token: The token that is not final + :type token: syntax.SemanticType + :param last_in_pile: The last element in the pile + :type last_in_pile: syntax.SemanticType + """ self.token = token if token: self.line = token.line_number