Skip to content

Commit d6e32b3

Browse files
committed
Move native primitive type check inside _to_primitive_tdl_type
1 parent 0696cac commit d6e32b3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

python/spider-py/src/spider_py/type/tdl_convert.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def _to_primitive_tdl_type(native_type: type | GenericAlias) -> TdlType | None:
2727
:param native_type:
2828
:return:
2929
- The converted TDL primitive if `native_type` is supported.
30-
- None otherwise.
30+
- None if `native_type` is not a primitive Python type.
31+
:raises TypeError: If `native_type` is a primitive Python type not supported by TDL.
3132
"""
3233
tdl_type: TdlType | None = None
3334
if native_type is Int8:
@@ -44,6 +45,11 @@ def _to_primitive_tdl_type(native_type: type | GenericAlias) -> TdlType | None:
4445
tdl_type = DoubleType()
4546
elif native_type is bool:
4647
tdl_type = BoolType()
48+
49+
if native_type in (int, float, str, complex, bytes):
50+
msg = f"{native_type} is not a TDL type. Please use the corresponding TDL primitive type."
51+
raise TypeError(msg)
52+
4753
return tdl_type
4854

4955

@@ -58,10 +64,6 @@ def to_tdl_type(native_type: type | GenericAlias) -> TdlType:
5864
if primitive_tdl_type is not None:
5965
return primitive_tdl_type
6066

61-
if native_type in (int, float, str, complex, bytes):
62-
msg = f"{native_type} is not a valid TDL type."
63-
raise TypeError(msg)
64-
6567
if isinstance(native_type, GenericAlias):
6668
origin = get_origin(native_type)
6769
if origin is list:

0 commit comments

Comments
 (0)