Skip to content

Commit

Permalink
fix: handle list
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Jul 15, 2024
1 parent c6b5d00 commit 6c6f0dd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
27 changes: 26 additions & 1 deletion backend/funix/decorator/magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ def get_type_dict(annotation: any) -> dict:
}
else:
raise Exception("Unsupported annotation")
elif annotation_type_class_name == "GenericAlias":
if getattr(annotation, "__name__") == "list":
return {"type": "list"}
elif getattr(annotation, "__name__") == "dict":
return {"type": "dict"}
else:
raise Exception("Unsupported annotation")
elif annotation_type_class_name == "_SpecialGenericAlias":
if (
getattr(annotation, "_name") == "Dict"
Expand Down Expand Up @@ -230,7 +237,10 @@ def get_type_widget_prop(
widget = (
"radio" if len(function_annotation.__args__) < 8 else "inputbox"
)
elif function_annotation_name == "List":
elif function_annotation_name == "List" or (
function_annotation_name == "list"
and hasattr(function_annotation, "__args__")
):
if args := getattr(function_annotation, "__args__"):
if getattr(args[0], "__name__") == "Literal":
widget = "checkbox" if len(args[0].__args__) < 8 else "inputbox"
Expand All @@ -249,6 +259,21 @@ def get_type_widget_prop(
elif function_arg_type_name.startswith("range"):
return {"type": "integer", "widget": widget}
elif function_arg_type_name == "list":
if type(function_annotation).__name__ == "GenericAlias" and hasattr(
function_annotation, "__args__"
):
arg = getattr(function_annotation, "__args__")[0]
return {
"type": "array",
"widget": widget,
"items": get_type_widget_prop(
getattr(arg, "__name__"),
index + 1,
function_arg_widget,
widget_type,
arg,
),
}
return {
"type": "array",
"items": {"type": "any", "widget": ""},
Expand Down
1 change: 0 additions & 1 deletion backend/funix/decorator/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def analyze_columns_and_default_value(pandas_like_anno):
widget = "json"
else:
if function_arg_type_dict["type"] in [
"list",
"dict",
"typing.Dict",
]:
Expand Down

0 comments on commit 6c6f0dd

Please sign in to comment.