From e96bd0816f27d220b65052dfd5b15ac31f6a8197 Mon Sep 17 00:00:00 2001 From: Qubasa Date: Thu, 30 Jan 2025 17:19:31 +0700 Subject: [PATCH] clan-cli: Expand type_to_dict to support NewType and tuple types in dataclasses --- pkgs/clan-cli/clan_cli/api/util.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/clan-cli/clan_cli/api/util.py b/pkgs/clan-cli/clan_cli/api/util.py index 72f16f543..ae884aea6 100644 --- a/pkgs/clan-cli/clan_cli/api/util.py +++ b/pkgs/clan-cli/clan_cli/api/util.py @@ -9,6 +9,7 @@ from typing import ( Annotated, Any, Literal, + NewType, NotRequired, Required, TypeVar, @@ -187,6 +188,10 @@ def type_to_dict( raise JSchemaTypeError(msg) return type_to_dict(type_map.get(t), scope, type_map) + if isinstance(t, NewType): + origtype = t.__supertype__ + return type_to_dict(origtype, scope, type_map) + if hasattr(t, "__origin__"): # Check if it's a generic type origin = get_origin(t) args = get_args(t) @@ -215,7 +220,7 @@ def type_to_dict( "oneOf": union_types, } - if origin in {list, set, frozenset}: + if origin in {list, set, frozenset, tuple}: return { "type": "array", "items": type_to_dict(t.__args__[0], scope, type_map),