diff options
author | Frederick Muriuki Muriithi | 2023-11-30 09:58:23 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2023-11-30 09:58:23 +0300 |
commit | 3b725c7354b185cc748f1d8ebfac6bab5e17b4aa (patch) | |
tree | 9154564b1ee696b1a954c1052a1e050bab7cd544 | |
parent | c26b9acc8d51bb5efe4e50114a6c723552e27a5f (diff) | |
download | gn-uploader-3b725c7354b185cc748f1d8ebfac6bab5e17b4aa.tar.gz |
Fix errors caught by pylint and mypy.
-rw-r--r-- | qc_app/errors.py | 8 | ||||
-rw-r--r-- | scripts/insert_data.py | 7 |
2 files changed, 10 insertions, 5 deletions
diff --git a/qc_app/errors.py b/qc_app/errors.py index 902e7e0..06c5dd4 100644 --- a/qc_app/errors.py +++ b/qc_app/errors.py @@ -5,12 +5,14 @@ import traceback import MySQLdb as mdb from flask import Flask, render_template -def handle_general_exception(exc: Exception): +def handle_general_exception(_exc: Exception): + """Handle generic exceptions.""" trace = traceback.format_exc() logging.error("Error: Generic unhandled exception!!\n%s", trace) return render_template("unhandled_exception.html", trace=trace) -def handle_general_MySQLdb_errors(exc: mdb.MySQLError): +def handle_general_mysqldb_errors(_exc: mdb.MySQLError): + """Handle MySQLdb errors.""" trace = traceback.format_exc() logging.error("MySQLError: Generic MySQL Error!!\n%s", trace) return render_template("unhandled_exception.html", trace=trace) @@ -18,4 +20,4 @@ def handle_general_MySQLdb_errors(exc: mdb.MySQLError): def register_error_handlers(app: Flask): """Register top-level error/exception handlers.""" app.register_error_handler(Exception, handle_general_exception) - app.register_error_handler(mdb.MySQLError, handle_general_exception) + app.register_error_handler(mdb.MySQLError, handle_general_mysqldb_errors) diff --git a/scripts/insert_data.py b/scripts/insert_data.py index 45b6dd5..4dbf27c 100644 --- a/scripts/insert_data.py +++ b/scripts/insert_data.py @@ -66,6 +66,7 @@ def strains_info( return {strain["Name"]: strain for strain in cursor.fetchall()} def read_datavalues(filepath, headings, strain_info): + """Read numerical, data values from the file.""" return { str(row["ProbeSetID"]): tuple({ "ProbeSetName": str(row["ProbeSetID"]), @@ -149,6 +150,7 @@ def insert_probesets(filepath: str, platform_id: int, headings: tuple[str, ...], session_rand_str: str) -> tuple[str, ...]: + """Save new ProbeSets into the database.""" probeset_query = ( "INSERT INTO ProbeSet(ChipId, Name) " "VALUES (%(ChipId)s, %(Name)s) ") @@ -157,7 +159,7 @@ def insert_probesets(filepath: str, "Name": f"{row['Name']}{session_rand_str}", "ChipId": platform_id } for row in read_probesets(filepath, headings)) - probeset_names = tuple() + probeset_names: tuple[str, ...] = tuple() with dbconn.cursor(cursorclass=DictCursor) as cursor: while True: probeset_params = tuple(take(the_probesets, 10000)) @@ -209,7 +211,8 @@ def insert_means(# pylint: disable=[too-many-locals, too-many-arguments] # which means that we cannot have 2 (or more) ProbeSets which share both # the name and chip_id (platform) at the same time. rand_str = f"::RAND_{random_string()}" - pset_ids = { + pset_ids = {# pylint: disable=[unnecessary-comprehension] + # Look into simply doing dict(probeset_ids(...)) name: pset_id for name, pset_id in probeset_ids( dbconn, |