1111import requests
1212from pydantic import BaseModel , validator
1313from 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 )
1616
1717import labelbox
1818from labelbox import utils
@@ -79,14 +79,13 @@ def _send_create_file_command(
7979 response_data = response_json .get ("data" , None )
8080 if response_data is None :
8181 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 ))
8483
8584 if not response_data .get ("createBulkImportRequest" , None ):
8685 raise labelbox .exceptions .LabelboxError (
8786 "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 ))
9089
9190 return response_data
9291
@@ -434,8 +433,7 @@ def _validate_ndjson(lines: Iterable[Dict[str, Any]],
434433 f'{ uuid } already used in this import job, '
435434 'must be unique for the project.' )
436435 uids .add (uuid )
437- except (pydantic .ValidationError , ValueError , TypeError ,
438- KeyError ) as e :
436+ except (pydantic .ValidationError , ValueError , TypeError , KeyError ) as e :
439437 raise labelbox .exceptions .MALValidationError (
440438 f"Invalid NDJson on line { idx } " ) from e
441439
@@ -519,6 +517,7 @@ class VideoSupported(BaseModel):
519517#Base class for a special kind of union.
520518# Compatible with pydantic. Improves error messages over a traditional union
521519class SpecialUnion :
520+
522521 def __new__ (cls , ** kwargs ):
523522 return cls .build (kwargs )
524523
@@ -656,11 +655,10 @@ def validate_answers(cls, value, field):
656655
657656 def validate_feature_schemas (self , valid_feature_schemas ):
658657 #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 )
661659 #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 ):
664662 raise ValueError (
665663 f"Duplicated featureSchema found for checklist { self .uuid } " )
666664 for answer in self .answers :
@@ -729,8 +727,7 @@ class NDPolygon(NDBaseTool):
729727 def is_geom_valid (cls , v ):
730728 if len (v ) < 3 :
731729 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 } " )
734731 return v
735732
736733
@@ -802,8 +799,7 @@ def is_valid_mask(cls, v):
802799 #Does the dtype matter? Can it be a float?
803800 if not isinstance (colors , (tuple , list )):
804801 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 } " )
807803 elif len (colors ) != 3 :
808804 raise ValueError (
809805 f"Must provide RGB values for segmentation colors. Found : { colors } "
@@ -819,14 +815,15 @@ class NDTool(
819815 SpecialUnion ,
820816 Type [Union [NDMask , # type: ignore
821817 NDTextEntity , NDPoint , NDRectangle , NDPolyline ,
822- NDPolygon , ]]):
818+ NDPolygon ,]]):
823819 ...
824820
825821
826822class NDAnnotation (
827823 SpecialUnion ,
828824 Type [Union [NDTool , # type: ignore
829825 NDClassification ]]):
826+
830827 @classmethod
831828 def build (cls : Any , data ) -> "NDBase" :
832829 if not isinstance (data , dict ):
0 commit comments