diff options
| author | Frederick Muriuki Muriithi | 2025-02-28 13:14:58 -0600 |
|---|---|---|
| committer | Frederick Muriuki Muriithi | 2025-02-28 13:14:58 -0600 |
| commit | 82f1d0da007019d949a39408c45425e00b22aa34 (patch) | |
| tree | aa6ed8bba4336317621043a3e1e7edc30433c6bf | |
| parent | f3a6c0adc3e5cb78c1a663fc686f00853729b5d7 (diff) | |
| download | genenetwork3-82f1d0da007019d949a39408c45425e00b22aa34.tar.gz | |
Fix issues caught by mypy.
| -rw-r--r-- | gn3/api/search.py | 14 | ||||
| -rw-r--r-- | gn3/authentication.py | 8 | ||||
| -rw-r--r-- | gn3/computations/correlations.py | 7 | ||||
| -rw-r--r-- | gn3/jobs.py | 2 |
4 files changed, 20 insertions, 11 deletions
diff --git a/gn3/api/search.py b/gn3/api/search.py index f696428..6aed2ad 100644 --- a/gn3/api/search.py +++ b/gn3/api/search.py @@ -6,7 +6,7 @@ import gzip import json from functools import partial, reduce from pathlib import Path -from typing import Callable +from typing import Union, Callable import urllib.parse from flask import abort, Blueprint, current_app, jsonify, request @@ -65,7 +65,10 @@ def field_processor_or(*field_processors: FieldProcessorFunction) -> FieldProces for field_processor in field_processors])) -def liftover(chain_file: Path, position: ChromosomalPosition) -> Maybe[ChromosomalPosition]: +def liftover( + chain_file: Union[str, Path], + position: ChromosomalPosition +) -> Maybe[ChromosomalPosition]: """Liftover chromosomal position using chain file.""" # The chain file format is described at # https://genome.ucsc.edu/goldenPath/help/chain.html @@ -91,7 +94,10 @@ def liftover(chain_file: Path, position: ChromosomalPosition) -> Maybe[Chromosom return Nothing -def liftover_interval(chain_file: str, interval: ChromosomalInterval) -> ChromosomalInterval: +def liftover_interval( + chain_file: Union[str, Path], + interval: ChromosomalInterval +) -> ChromosomalInterval: """ Liftover interval using chain file. @@ -258,7 +264,7 @@ def parse_query(synteny_files_directory: Path, query: str): xapian.Query(species_prefix + lifted_species), chromosome_prefix, range_prefixes.index("position"), - partial(liftover_interval, + partial(liftover_interval,# type: ignore[arg-type] synteny_files_directory / chain_file))) queryparser.add_boolean_prefix( shorthand, diff --git a/gn3/authentication.py b/gn3/authentication.py index e7e4543..fac6ed9 100644 --- a/gn3/authentication.py +++ b/gn3/authentication.py @@ -61,7 +61,7 @@ def get_user_membership(conn: Redis, user_id: str, """ results = {"member": False, "admin": False} - for key, value in conn.hgetall('groups').items(): + for key, value in conn.hgetall('groups').items():# type: ignore[union-attr] if key == group_id: group_info = json.loads(value) if user_id in group_info.get("admins"): @@ -114,7 +114,7 @@ def get_groups_by_user_uid(user_uid: str, conn: Redis) -> Dict: """ admin = [] member = [] - for group_uuid, group_info in conn.hgetall("groups").items(): + for group_uuid, group_info in conn.hgetall("groups").items():# type: ignore[union-attr] group_info = json.loads(group_info) group_info["uuid"] = group_uuid if user_uid in group_info.get('admins'): @@ -131,14 +131,14 @@ def get_user_info_by_key(key: str, value: str, conn: Redis) -> Optional[Dict]: """Given a key, get a user's information if value is matched""" if key != "user_id": - for user_uuid, user_info in conn.hgetall("users").items(): + for user_uuid, user_info in conn.hgetall("users").items():# type: ignore[union-attr] user_info = json.loads(user_info) if (key in user_info and user_info.get(key) == value): user_info["user_id"] = user_uuid return user_info elif key == "user_id": if user_info := conn.hget("users", value): - user_info = json.loads(user_info) + user_info = json.loads(user_info)# type: ignore[arg-type] user_info["user_id"] = value return user_info return None diff --git a/gn3/computations/correlations.py b/gn3/computations/correlations.py index e5934b6..95bd957 100644 --- a/gn3/computations/correlations.py +++ b/gn3/computations/correlations.py @@ -6,6 +6,7 @@ from multiprocessing import Pool, cpu_count from typing import List from typing import Tuple +from typing import Sequence from typing import Optional from typing import Callable from typing import Generator @@ -52,8 +53,10 @@ def normalize_values(a_values: List, b_values: List) -> Generator: yield a_val, b_val -def compute_corr_coeff_p_value(primary_values: List, target_values: List, - corr_method: str) -> Tuple[float, float]: +def compute_corr_coeff_p_value( + primary_values: Sequence, + target_values: Sequence, + corr_method: str) -> Tuple[float, float]: """Given array like inputs calculate the primary and target_value methods -> pearson,spearman and biweight mid correlation return value is rho and p_value diff --git a/gn3/jobs.py b/gn3/jobs.py index 1af63f7..898517c 100644 --- a/gn3/jobs.py +++ b/gn3/jobs.py @@ -24,7 +24,7 @@ def job(redisconn: Redis, job_id: UUID) -> Either: if the_job: return Right({ key: json.loads(value, object_hook=jed.custom_json_decoder) - for key, value in the_job.items() + for key, value in the_job.items()# type: ignore[union-attr] }) return Left({ "error": "NotFound", |
