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