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
@@ -434,8 +433,7 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
434
433
f'{ uuid } already used in this import job, '
435
434
'must be unique for the project.' )
436
435
uids .add (uuid )
437
- except (pydantic .ValidationError , ValueError , TypeError ,
438
- KeyError ) as e :
436
+ except (pydantic .ValidationError , ValueError , TypeError , KeyError ) as e :
439
437
raise labelbox .exceptions .MALValidationError (
440
438
f"Invalid NDJson on line { idx } " ) from e
441
439
@@ -519,6 +517,7 @@ class VideoSupported(BaseModel):
519
517
#Base class for a special kind of union.
520
518
# Compatible with pydantic. Improves error messages over a traditional union
521
519
class SpecialUnion :
520
+
522
521
def __new__ (cls , ** kwargs ):
523
522
return cls .build (kwargs )
524
523
@@ -656,11 +655,10 @@ def validate_answers(cls, value, field):
656
655
657
656
def validate_feature_schemas (self , valid_feature_schemas ):
658
657
#Test top level feature schema for this tool
659
- super (NDChecklist ,
660
- self ).validate_feature_schemas (valid_feature_schemas )
658
+ super (NDChecklist , self ).validate_feature_schemas (valid_feature_schemas )
661
659
#Test the feature schemas provided to the answer field
662
- if len (set ([answer .schemaId
663
- for answer in self . answers ])) != len ( self .answers ):
660
+ if len (set ([answer .schemaId for answer in self . answers ])) != len (
661
+ self .answers ):
664
662
raise ValueError (
665
663
f"Duplicated featureSchema found for checklist { self .uuid } " )
666
664
for answer in self .answers :
@@ -729,8 +727,7 @@ class NDPolygon(NDBaseTool):
729
727
def is_geom_valid (cls , v ):
730
728
if len (v ) < 3 :
731
729
raise ValueError (
732
- f"A polygon must have at least 3 points to be valid. Found { v } "
733
- )
730
+ f"A polygon must have at least 3 points to be valid. Found { v } " )
734
731
return v
735
732
736
733
@@ -802,8 +799,7 @@ def is_valid_mask(cls, v):
802
799
#Does the dtype matter? Can it be a float?
803
800
if not isinstance (colors , (tuple , list )):
804
801
raise ValueError (
805
- f"Received color that is not a list or tuple. Found : { colors } "
806
- )
802
+ f"Received color that is not a list or tuple. Found : { colors } " )
807
803
elif len (colors ) != 3 :
808
804
raise ValueError (
809
805
f"Must provide RGB values for segmentation colors. Found : { colors } "
@@ -819,14 +815,15 @@ class NDTool(
819
815
SpecialUnion ,
820
816
Type [Union [NDMask , # type: ignore
821
817
NDTextEntity , NDPoint , NDRectangle , NDPolyline ,
822
- NDPolygon , ]]):
818
+ NDPolygon ,]]):
823
819
...
824
820
825
821
826
822
class NDAnnotation (
827
823
SpecialUnion ,
828
824
Type [Union [NDTool , # type: ignore
829
825
NDClassification ]]):
826
+
830
827
@classmethod
831
828
def build (cls : Any , data ) -> "NDBase" :
832
829
if not isinstance (data , dict ):
0 commit comments