Skip to content

Commit 1d0b49b

Browse files
committed
Enhance fill_query_results to check function signature for short_form argument handling
1 parent 14fe1f3 commit 1d0b49b

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/vfbquery/vfb_queries.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import time
1515
import requests
1616
from concurrent.futures import ThreadPoolExecutor
17+
import inspect
1718

1819
# Custom JSON encoder to handle NumPy and pandas types
1920
class NumpyEncoder(json.JSONEncoder):
@@ -895,7 +896,6 @@ def term_info_parse_object(results, short_form):
895896
synonym["scope"] = syn.synonym.scope if hasattr(syn.synonym, 'scope') else "exact"
896897
synonym["type"] = syn.synonym.type if hasattr(syn.synonym, 'type') else "synonym"
897898

898-
# Enhanced publication handling - handle multiple publications
899899
if hasattr(syn, 'pubs') and syn.pubs:
900900
pub_refs = []
901901
for pub in syn.pubs:
@@ -3833,16 +3833,23 @@ def process_query(query):
38333833
function_args = query['takes'].get("default", {})
38343834
# print(f"Function args: {function_args}")
38353835

3836+
# Check function signature to see if it takes a positional argument for short_form
3837+
sig = inspect.signature(function)
3838+
params = list(sig.parameters.keys())
3839+
# Skip 'self' if it's a method, and check if first param is not return_dataframe/limit/summary_mode
3840+
first_param = params[1] if params and params[0] == 'self' else (params[0] if params else None)
3841+
takes_short_form = first_param and first_param not in ['return_dataframe', 'limit', 'summary_mode']
3842+
38363843
# Modify this line to use the correct arguments and pass the default arguments
38373844
if summary_mode:
3838-
if function_args:
3845+
if function_args and takes_short_form:
38393846
# Pass the short_form as positional argument
38403847
short_form_value = list(function_args.values())[0]
38413848
result = function(short_form_value, return_dataframe=False, limit=query['preview'], summary_mode=summary_mode)
38423849
else:
38433850
result = function(return_dataframe=False, limit=query['preview'], summary_mode=summary_mode)
38443851
else:
3845-
if function_args:
3852+
if function_args and takes_short_form:
38463853
short_form_value = list(function_args.values())[0]
38473854
result = function(short_form_value, return_dataframe=False, limit=query['preview'])
38483855
else:

0 commit comments

Comments
 (0)