Skip to content

Commit 85a214e

Browse files
committed
updating some type hints and also updating a grammatic error for tiled imagery
1 parent 9ce5724 commit 85a214e

File tree

12 files changed

+48
-39
lines changed

12 files changed

+48
-39
lines changed

labelbox/data/annotation_types/classification/classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ClassificationAnswer(FeatureSchema):
3333
extra: Dict[str, Any] = {}
3434
keyframe: Optional[bool] = None
3535

36-
def dict(self, *args, **kwargs):
36+
def dict(self, *args, **kwargs) -> Dict[str, str]:
3737
res = super().dict(*args, **kwargs)
3838
if res['keyframe'] is None:
3939
res.pop('keyframe')

labelbox/data/annotation_types/collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _ensure_unique_external_ids(self) -> None:
133133
)
134134
external_ids.add(label.data.external_id)
135135

136-
def append(self, label: Label):
136+
def append(self, label: Label) -> None:
137137
self._data.append(label)
138138

139139
def __iter__(self) -> "LabelList":

labelbox/data/annotation_types/data/raster.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class RasterData(BaseModel, ABC):
2323

2424
@classmethod
2525
def from_2D_arr(cls, arr: Union[TypedArray[Literal['uint8']],
26-
TypedArray[Literal['int']]], **kwargs):
26+
TypedArray[Literal['int']]],
27+
**kwargs) -> "RasterData":
2728
"""Construct from a 2D numpy array
2829
2930
Args:

labelbox/data/annotation_types/data/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TextData(BaseData):
1111
"""
1212
Represents text data. Requires arg file_path, text, or url
1313
14-
>>> TextData(text="")
14+
>>> TextData(text="")
1515
1616
Args:
1717
file_path (str)

labelbox/data/annotation_types/data/tiled_image.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class TileLayer(BaseModel):
9999
url: str
100100
name: Optional[str] = "default"
101101

102-
def asdict(self) -> Dict:
102+
def asdict(self) -> Dict[str, str]:
103103
return {"tileLayerUrl": self.url, "name": self.name}
104104

105105
@validator('url')
@@ -142,7 +142,7 @@ def __post_init__(self) -> None:
142142
if self.max_native_zoom is None:
143143
self.max_native_zoom = self.zoom_levels[0]
144144

145-
def asdict(self) -> Dict:
145+
def asdict(self) -> Dict[str, str]:
146146
return {
147147
"tileLayerUrl": self.tile_layer.url,
148148
"bounds": [[
@@ -415,7 +415,7 @@ def geo_and_pixel(cls,
415415

416416
if src_epsg == EPSG.SIMPLEPIXEL:
417417

418-
def transform(x: int, y: int) -> Callable:
418+
def transform(x: int, y: int) -> Callable[[int, int], Transformer]:
419419
scaled_xy = (x * (global_x_range) / (local_x_range),
420420
y * (global_y_range) / (local_y_range))
421421

@@ -435,7 +435,7 @@ def transform(x: int, y: int) -> Callable:
435435
#handles 4326 from lat,lng
436436
elif src_epsg == EPSG.EPSG4326:
437437

438-
def transform(x: int, y: int) -> Callable:
438+
def transform(x: int, y: int) -> Callable[[int, int], Transformer]:
439439
point_in_px = PygeoPoint.from_latitude_longitude(
440440
latitude=y, longitude=x).pixels(zoom)
441441

@@ -450,7 +450,7 @@ def transform(x: int, y: int) -> Callable:
450450
#handles 3857 from meters
451451
elif src_epsg == EPSG.EPSG3857:
452452

453-
def transform(x: int, y: int) -> Callable:
453+
def transform(x: int, y: int) -> Callable[[int, int], Transformer]:
454454
point_in_px = PygeoPoint.from_meters(meter_y=y,
455455
meter_x=x).pixels(zoom)
456456

@@ -463,8 +463,9 @@ def transform(x: int, y: int) -> Callable:
463463
return transform
464464

465465
@classmethod
466-
def create_geo_to_geo_transformer(cls, src_epsg: EPSG,
467-
tgt_epsg: EPSG) -> Callable:
466+
def create_geo_to_geo_transformer(
467+
cls, src_epsg: EPSG,
468+
tgt_epsg: EPSG) -> Callable[[int, int], Transformer]:
468469
"""method to change from one projection to another projection.
469470
470471
supports EPSG transformations not Simple.
@@ -478,11 +479,12 @@ def create_geo_to_geo_transformer(cls, src_epsg: EPSG,
478479
src_epsg.value, tgt_epsg.value, always_xy=True).transform)
479480

480481
@classmethod
481-
def create_geo_to_pixel_transformer(cls,
482-
src_epsg,
483-
pixel_bounds: TiledBounds,
484-
geo_bounds: TiledBounds,
485-
zoom=0) -> Callable:
482+
def create_geo_to_pixel_transformer(
483+
cls,
484+
src_epsg,
485+
pixel_bounds: TiledBounds,
486+
geo_bounds: TiledBounds,
487+
zoom=0) -> Callable[[int, int], Transformer]:
486488
"""method to change from a geo projection to Simple"""
487489

488490
transform_function = cls.geo_and_pixel(src_epsg=src_epsg,
@@ -492,11 +494,12 @@ def create_geo_to_pixel_transformer(cls,
492494
return EPSGTransformer(transformer=transform_function)
493495

494496
@classmethod
495-
def create_pixel_to_geo_transformer(cls,
496-
src_epsg,
497-
pixel_bounds: TiledBounds,
498-
geo_bounds: TiledBounds,
499-
zoom=0) -> Callable:
497+
def create_pixel_to_geo_transformer(
498+
cls,
499+
src_epsg,
500+
pixel_bounds: TiledBounds,
501+
geo_bounds: TiledBounds,
502+
zoom=0) -> Callable[[int, int], Transformer]:
500503
"""method to change from a geo projection to Simple"""
501504
transform_function = cls.geo_and_pixel(src_epsg=src_epsg,
502505
pixel_bounds=pixel_bounds,

labelbox/data/annotation_types/geometry/mask.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Optional, Tuple, Union
1+
from typing import Callable, Optional, Tuple, Union, Dict
22

33
import numpy as np
44
from pydantic.class_validators import validator
@@ -37,7 +37,7 @@ class Mask(Geometry):
3737
color: Union[Tuple[int, int, int], int]
3838

3939
@property
40-
def geometry(self):
40+
def geometry(self) -> Dict[str, Tuple[int, int, int]]:
4141
mask = self.draw(color=1)
4242
polygons = (
4343
shape(shp)

labelbox/data/annotation_types/geometry/rectangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ def draw(self,
5555
return cv2.polylines(canvas, pts, True, color, thickness)
5656

5757
@classmethod
58-
def from_xyhw(cls, x: float, y: float, h: float, w: float):
58+
def from_xyhw(cls, x: float, y: float, h: float, w: float) -> "Rectangle":
5959
"""Create Rectangle from x,y, height width format"""
6060
return cls(start=Point(x=x, y=y), end=Point(x=x + w, y=y + h))

labelbox/data/ontology.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Tuple
1+
from typing import Dict, List, Tuple, Union
22

33
from labelbox.schema import ontology
44
from .annotation_types import (Text, Dropdown, Checklist, Radio,
@@ -84,8 +84,9 @@ def get_classifications(
8484
return list(existing_classifications.values())
8585

8686

87-
def get_tools(annotations: List[ObjectAnnotation],
88-
existing_tools: List[ontology.Classification]):
87+
def get_tools(
88+
annotations: List[ObjectAnnotation],
89+
existing_tools: List[ontology.Classification]) -> List[ontology.Tool]:
8990
existing_tools = {tool.name: tool for tool in existing_tools}
9091
for annotation in annotations:
9192
if annotation.name in existing_tools:
@@ -103,7 +104,8 @@ def get_tools(annotations: List[ObjectAnnotation],
103104
return list(existing_tools.values())
104105

105106

106-
def tool_mapping(annotation):
107+
def tool_mapping(
108+
annotation) -> Union[Mask, Polygon, Point, Rectangle, Line, TextEntity]:
107109
tool_types = ontology.Tool.Type
108110
mapping = {
109111
Mask: tool_types.SEGMENTATION,
@@ -121,7 +123,8 @@ def tool_mapping(annotation):
121123
return result
122124

123125

124-
def classification_mapping(annotation):
126+
def classification_mapping(
127+
annotation) -> Union[Text, Checklist, Radio, Dropdown]:
125128
classification_types = ontology.Classification.Type
126129
mapping = {
127130
Text: classification_types.TEXT,

labelbox/data/serialization/labelbox_v1/classification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def from_common(cls, dropdown: Dropdown, feature_schema_id: Cuid,
8181
class LBV1Text(LBV1Feature):
8282
answer: str
8383

84-
def to_common(self):
84+
def to_common(self) -> Text:
8585
return Text(answer=self.answer)
8686

8787
@classmethod

labelbox/data/serialization/labelbox_v1/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class LBV1Converter:
2020

2121
@staticmethod
2222
def deserialize_video(json_data: Iterable[Dict[str, Any]],
23-
client: "labelbox.Client"):
23+
client: "labelbox.Client") -> LabelGenerator:
2424
"""
2525
Converts a labelbox video export into the common labelbox format.
2626

0 commit comments

Comments
 (0)