11
11
import requests
12
12
from pydantic import BaseModel , validator
13
13
from typing_extensions import Literal
14
- from typing import (Any , List , Optional , BinaryIO , Dict , Iterable , Tuple ,
15
- Union , Type , Set )
14
+ from typing import (Any , List , Optional , BinaryIO , Dict , Iterable , Tuple , Union ,
15
+ Type , Set )
16
16
17
17
import labelbox
18
18
from labelbox import utils
@@ -79,14 +79,13 @@ def _send_create_file_command(
79
79
response_data = response_json .get ("data" , None )
80
80
if response_data is None :
81
81
raise labelbox .exceptions .LabelboxError (
82
- "Failed to upload, message: %s" %
83
- response_json .get ("errors" , None ))
82
+ "Failed to upload, message: %s" % response_json .get ("errors" , None ))
84
83
85
84
if not response_data .get ("createBulkImportRequest" , None ):
86
85
raise labelbox .exceptions .LabelboxError (
87
86
"Failed to create BulkImportRequest, message: %s" %
88
- response_json .get ("errors" , None )
89
- or response_data .get ("error" , None ))
87
+ response_json .get ("errors" , None ) or
88
+ response_data .get ("error" , None ))
90
89
91
90
return response_data
92
91
@@ -435,8 +434,7 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
435
434
f'{ uuid } already used in this import job, '
436
435
'must be unique for the project.' )
437
436
uids .add (uuid )
438
- except (pydantic .ValidationError , ValueError , TypeError ,
439
- KeyError ) as e :
437
+ except (pydantic .ValidationError , ValueError , TypeError , KeyError ) as e :
440
438
raise labelbox .exceptions .MALValidationError (
441
439
f"Invalid NDJson on line { idx } " ) from e
442
440
@@ -520,6 +518,7 @@ class VideoSupported(BaseModel):
520
518
#Base class for a special kind of union.
521
519
# Compatible with pydantic. Improves error messages over a traditional union
522
520
class SpecialUnion :
521
+
523
522
def __new__ (cls , ** kwargs ):
524
523
return cls .build (kwargs )
525
524
@@ -657,11 +656,10 @@ def validate_answers(cls, value, field):
657
656
658
657
def validate_feature_schemas (self , valid_feature_schemas ):
659
658
#Test top level feature schema for this tool
660
- super (NDChecklist ,
661
- self ).validate_feature_schemas (valid_feature_schemas )
659
+ super (NDChecklist , self ).validate_feature_schemas (valid_feature_schemas )
662
660
#Test the feature schemas provided to the answer field
663
- if len (set ([answer .schemaId
664
- for answer in self . answers ])) != len ( self .answers ):
661
+ if len (set ([answer .schemaId for answer in self . answers ])) != len (
662
+ self .answers ):
665
663
raise ValueError (
666
664
f"Duplicated featureSchema found for checklist { self .uuid } " )
667
665
for answer in self .answers :
@@ -730,8 +728,7 @@ class NDPolygon(NDBaseTool):
730
728
def is_geom_valid (cls , v ):
731
729
if len (v ) < 3 :
732
730
raise ValueError (
733
- f"A polygon must have at least 3 points to be valid. Found { v } "
734
- )
731
+ f"A polygon must have at least 3 points to be valid. Found { v } " )
735
732
return v
736
733
737
734
@@ -803,8 +800,7 @@ def is_valid_mask(cls, v):
803
800
#Does the dtype matter? Can it be a float?
804
801
if not isinstance (colors , (tuple , list )):
805
802
raise ValueError (
806
- f"Received color that is not a list or tuple. Found : { colors } "
807
- )
803
+ f"Received color that is not a list or tuple. Found : { colors } " )
808
804
elif len (colors ) != 3 :
809
805
raise ValueError (
810
806
f"Must provide RGB values for segmentation colors. Found : { colors } "
@@ -820,14 +816,15 @@ class NDTool(
820
816
SpecialUnion ,
821
817
Type [Union [NDMask , # type: ignore
822
818
NDTextEntity , NDPoint , NDRectangle , NDPolyline ,
823
- NDPolygon , ]]):
819
+ NDPolygon ,]]):
824
820
...
825
821
826
822
827
823
class NDAnnotation (
828
824
SpecialUnion ,
829
825
Type [Union [NDTool , # type: ignore
830
826
NDClassification ]]):
827
+
831
828
@classmethod
832
829
def build (cls : Any , data ) -> "NDBase" :
833
830
if not isinstance (data , dict ):
0 commit comments