Skip to content

Commit

Permalink
add some type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Jul 21, 2023
1 parent 0cd940e commit 4f1cd25
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ test = [
"pytest-cov >=3.0.0",
"pre-commit",
"mypy >=0.991",
"types-requests",
]
doc = [
"mkdocs >=1.4.2",
Expand Down Expand Up @@ -129,7 +130,7 @@ warn_unused_ignores = true
warn_redundant_casts = true
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_any_generics = true
disallow_any_generics = false


[tool.pytest.ini_options]
Expand Down
3 changes: 2 additions & 1 deletion src/trapi_predict_kit/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
from typing import Optional

from pydantic import BaseSettings


class Settings(BaseSettings):
VIRTUAL_HOST: str = None
VIRTUAL_HOST: Optional[str] = None
TIMEOUT: int = 30

DEV_MODE: bool = False
Expand Down
8 changes: 4 additions & 4 deletions src/trapi_predict_kit/decorators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import functools
from typing import Dict, List, Optional
from typing import Any, Callable, Dict, List, Optional

from reasoner_pydantic import MetaEdge, MetaNode

Expand All @@ -14,16 +14,16 @@ def trapi_predict(
description: Optional[str] = "",
default_input: Optional[str] = "drugbank:DB00394",
default_model: Optional[str] = "openpredict_baseline",
):
) -> Callable:
"""A decorator to indicate a function is a function to generate prediction that can be integrated to TRAPI.
The function needs to take an input_id and returns a list of predicted entities related to the input entity
"""
if not name:
name = path

def decorator(func):
def decorator(func: Callable) -> Any:
@functools.wraps(func)
def wrapper(input_id: str, options: Optional[PredictOptions] = None):
def wrapper(input_id: str, options: Optional[PredictOptions] = None) -> Callable:
options = PredictOptions.parse_obj(options) if options else PredictOptions()
return func(input_id, options)

Expand Down
4 changes: 2 additions & 2 deletions src/trapi_predict_kit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
log.addHandler(console_handler)


def get_openpredict_dir(subfolder=""):
def get_openpredict_dir(subfolder: str = "") -> str:
"""Return the full path to the provided files in the OpenPredict data folder
Where models and features for runs are stored
"""
Expand All @@ -26,7 +26,7 @@ def get_openpredict_dir(subfolder=""):
return settings.OPENPREDICT_DATA_DIR + subfolder


def init_openpredict_dir():
def init_openpredict_dir() -> None:
"""Create OpenPredict folder and initiate files if necessary."""
if not os.path.exists(get_openpredict_dir("input/drugbank-drug-goa.csv")):
raise ValueError(
Expand Down

0 comments on commit 4f1cd25

Please sign in to comment.