From 2609702e8c18b5c797dfc25966c3bd479c8e7ec5 Mon Sep 17 00:00:00 2001 From: Kevin Kazmierczak Date: Tue, 9 Jan 2024 10:58:04 -0500 Subject: [PATCH] feat(130): Type hinting and cleanup --- src/biocommons/seqrepo/config.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/biocommons/seqrepo/config.py b/src/biocommons/seqrepo/config.py index fb40b1f..d10c582 100644 --- a/src/biocommons/seqrepo/config.py +++ b/src/biocommons/seqrepo/config.py @@ -1,21 +1,22 @@ import os +from typing import Optional -def parse_caching_env_var(env_name, env_default): - seqrepo_env_var = os.environ.get(env_name, env_default) - if seqrepo_env_var.lower() == "none": +def parse_caching_env_var(env_name: str, env_default: str) -> Optional[int]: + caching_env_var = os.environ.get(env_name, env_default) + if caching_env_var.lower() == "none": return None try: - seqrepo_env_var_int = int(seqrepo_env_var) + caching_env_var_int = int(caching_env_var) except ValueError: raise ValueError( f"{env_name} must be a valid int, none, or not set, " - "currently it is " + seqrepo_env_var + "currently it is " + caching_env_var ) - return seqrepo_env_var_int + return caching_env_var_int SEQREPO_LRU_CACHE_MAXSIZE = parse_caching_env_var("SEQREPO_LRU_CACHE_MAXSIZE", "1000000") -# Using a default value here of -1 to differentiate not setting this value and an explicit None (unbounded cache) +# Using a default value here of -1 to differentiate not setting this env var and an explicit None (unbounded cache) SEQREPO_FD_CACHE_MAXSIZE = parse_caching_env_var("SEQREPO_FD_CACHE_MAXSIZE", "-1")