@@ -53,7 +53,7 @@ class FieldType(Enum):
5353 CHOICE = "choice" # allows only one selection
5454 RADIO = "radio"
5555
56- def __str__ (self ):
56+ def __str__ (self ) -> str :
5757 return self .value
5858
5959
@@ -131,7 +131,7 @@ def __init__(
131131 self .configs .update (configs )
132132
133133 @classmethod
134- def make_textbox (cls , label : str , field_bbox : BoundingBox , font_size ) :
134+ def make_textbox (cls , label : str , field_bbox : BoundingBox , font_size : int ) -> "FormField" :
135135 return FormField (
136136 label ,
137137 FieldType .TEXT ,
@@ -142,7 +142,7 @@ def make_textbox(cls, label: str, field_bbox: BoundingBox, font_size):
142142 )
143143
144144 @classmethod
145- def make_textarea (cls , label : str , field_bbox : BoundingBox , font_size ) :
145+ def make_textarea (cls , label : str , field_bbox : BoundingBox , font_size : int ) -> "FormField" :
146146 return FormField (
147147 label ,
148148 FieldType .AREA ,
@@ -153,7 +153,7 @@ def make_textarea(cls, label: str, field_bbox: BoundingBox, font_size):
153153 )
154154
155155 @classmethod
156- def make_checkbox (cls , label : str , bbox : BoundingBox ):
156+ def make_checkbox (cls , label : str , bbox : BoundingBox ) -> "FormField" :
157157 return FormField (
158158 label ,
159159 FieldType .CHECK_BOX ,
@@ -163,7 +163,7 @@ def make_checkbox(cls, label: str, bbox: BoundingBox):
163163 )
164164
165165 @classmethod
166- def from_pikefield (cls , pike_field : PikeField ):
166+ def from_pikefield (cls , pike_field : PikeField ) -> "FormField" :
167167 if pike_field ["type" ] == "/Tx" :
168168 var_type = FieldType .TEXT
169169 elif pike_field ["type" ] == "/Btn" :
@@ -174,10 +174,10 @@ def from_pikefield(cls, pike_field: PikeField):
174174 var_type = FieldType .TEXT
175175
176176 if hasattr (pike_field ["all" ], "Rect" ):
177- x = float (pike_field ["all" ].Rect [0 ]) # type: ignore
178- y = float (pike_field ["all" ].Rect [1 ]) # type: ignore
179- width = float (pike_field ["all" ].Rect [2 ]) - x # type: ignore
180- height = float (pike_field ["all" ].Rect [3 ]) - y # type: ignore
177+ x = float (pike_field ["all" ].Rect [0 ])
178+ y = float (pike_field ["all" ].Rect [1 ])
179+ width = float (pike_field ["all" ].Rect [2 ]) - x
180+ height = float (pike_field ["all" ].Rect [3 ]) - y
181181 else :
182182 x = 0
183183 y = 0
@@ -1134,8 +1134,12 @@ def get_possible_radios(img: Union[str, BinaryIO, cv2.Mat]):
11341134 if isinstance (img , str ):
11351135 # 0 is for the flags: means nothing special is being used
11361136 img_mat = cv2 .imread (img , 0 )
1137+ if img_mat is None :
1138+ return []
11371139 elif isinstance (img , BinaryIO ):
11381140 img_mat = cv2 .imdecode (np .frombuffer (img .read (), np .uint8 ), 0 )
1141+ if img_mat is None :
1142+ return []
11391143 else :
11401144 img_mat = img
11411145
@@ -1184,8 +1188,12 @@ def get_possible_text_fields(
11841188 if isinstance (img , str ):
11851189 # 0 is for the flags: means nothing special is being used
11861190 img_mat = cv2 .imread (img , 0 )
1191+ if img_mat is None :
1192+ return []
11871193 elif isinstance (img , BinaryIO ):
11881194 img_mat = cv2 .imdecode (np .frombuffer (img .read (), np .uint8 ), 0 )
1195+ if img_mat is None :
1196+ return []
11891197 else :
11901198 img_mat = img
11911199
0 commit comments