From 35358c2bc09959cefce30865557298bbeaab0fa4 Mon Sep 17 00:00:00 2001 From: John Nduli Date: Thu, 13 Jun 2024 18:50:27 +0300 Subject: fix: typehints in index-genenetwork script --- gn3/db_utils.py | 2 +- scripts/index-genenetwork | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gn3/db_utils.py b/gn3/db_utils.py index 19537d4..0d9bd0a 100644 --- a/gn3/db_utils.py +++ b/gn3/db_utils.py @@ -39,7 +39,7 @@ def database_connection(sql_uri: str, logger: logging.Logger = LOGGER) -> Iterat try: yield connection except mdb.Error as _mbde: - logger.error("DB error encountered", exc_info=1) + logger.error("DB error encountered", exc_info=True) connection.rollback() finally: connection.commit() diff --git a/scripts/index-genenetwork b/scripts/index-genenetwork index e0f6d81..ebf04e7 100755 --- a/scripts/index-genenetwork +++ b/scripts/index-genenetwork @@ -190,8 +190,11 @@ _:node rdf:type gnc:GNWikiEntry ; } GROUP BY ?speciesName ?symbolName """ sparql.setQuery(query) - results = sparql.queryAndConvert()["results"]["bindings"] - for entry in results: + results = sparql.queryAndConvert() + if not isinstance(results, dict): + raise TypeError(f"Expected results to be a dict but found {type(results)}") + bindings = results["results"]["bindings"] + for entry in bindings : x = (entry["speciesName"]["value"], entry["symbolName"]["value"],) cache[x] = entry["comment"]["value"] return cache @@ -221,8 +224,11 @@ _:node rdf:type gnc:GNWikiEntry ; } GROUP BY ?type """ sparql.setQuery(query) - results = sparql.queryAndConvert()["results"]["bindings"] - return results[0]["hash"]["value"] + results = sparql.queryAndConvert() + if not isinstance(results, dict): + raise TypeError(f"Expected results to be a dict but found {type(results)}") + bindings = results["results"]["bindings"] + return bindings[0]["hash"]["value"] # pylint: disable=invalid-name @@ -456,7 +462,7 @@ def is_data_modified(xapian_directory: str, dir_ = pathlib.Path(xapian_directory) with locked_xapian_writable_database(dir_) as db, database_connection(sql_uri) as conn: checksums = " ".join([ - result["Checksum"].bind(str) + str(result["Checksum"].value) for result in query_sql( conn, f"CHECKSUM TABLE {', '.join(db.get_metadata('tables').decode().split())}") -- cgit v1.2.3