11from enum import Enum
22from importlib import import_module
3+ from typing import TYPE_CHECKING , Union
34
45from mindee .error import MindeeApiV2Error
56from mindee .parsing .common .string_dict import StringDict
67
8+ if TYPE_CHECKING :
9+ from mindee .parsing .v2 .field .list_field import ListField
10+ from mindee .parsing .v2 .field .object_field import ObjectField
11+ from mindee .parsing .v2 .field .simple_field import SimpleField
12+
713
814class FieldType (str , Enum ):
915 """Field types."""
@@ -13,6 +19,9 @@ class FieldType(str, Enum):
1319 SIMPLE = "SimpleField"
1420
1521
22+ FieldTypeAlias = Union ["SimpleField" , "ListField" , "ObjectField" ]
23+
24+
1625class DynamicField :
1726 """Field that can be displayed in rst format."""
1827
@@ -30,7 +39,10 @@ def multi_str(self) -> str:
3039 return str (self )
3140
3241
33- def get_field_type (raw_response : StringDict , indent_level : int = 0 ) -> DynamicField :
42+ def get_field_type (
43+ raw_response : StringDict ,
44+ indent_level : int = 0 ,
45+ ) -> FieldTypeAlias :
3446 """Get appropriate field types."""
3547 if isinstance (raw_response , dict ):
3648 if "value" in raw_response :
@@ -43,7 +55,7 @@ def get_field_type(raw_response: StringDict, indent_level: int = 0) -> DynamicFi
4355 field_file = import_module ("mindee.parsing.v2.field.object_field" )
4456 field_class = getattr (field_file , FieldType .OBJECT .value )
4557 else :
46- raise MindeeApiV2Error (f"Unrecognized field format in { raw_response } ." )
58+ raise MindeeApiV2Error (f"Unrecognized field type in { raw_response } ." )
4759 return field_class (raw_response , indent_level )
4860
4961 raise MindeeApiV2Error (f"Unrecognized field format { raw_response } ." )
0 commit comments