Skip to content

Commit 4030339

Browse files
Fix typing
1 parent 9d94e24 commit 4030339

File tree

2 files changed

+68
-77
lines changed

2 files changed

+68
-77
lines changed

encord/objects/coordinates.py

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -23,74 +23,23 @@
2323
from encord.objects.html_node import HtmlRange
2424
from encord.objects.types import (
2525
BaseFrameObject,
26+
BoundingBoxDict,
27+
BoundingBoxFrameCoordinatesDict,
2628
FrameObject,
27-
PointFrameObject2D,
28-
PointFrameObject3D,
29-
PolygonFrameObject,
30-
PolylineFrameObject,
29+
Point3DFrameCoordinatesDict,
30+
PointDict,
31+
PointDict3D,
32+
PointFrameCoordinatesDict,
33+
PolygonFrameCoordinatesDict,
34+
PolylineFrameCoordinatesDict,
35+
RotatableBoundingBoxDict,
36+
RotatableBoundingBoxFrameCoordinatesDict,
3137
)
3238
from encord.orm.analytics import CamelStrEnum
3339
from encord.orm.base_dto import BaseDTO
3440

3541
logger = logging.getLogger(__name__)
3642

37-
""" Typed Dicts for Shape Coordinates """
38-
39-
40-
class BoundingBoxDict(TypedDict):
41-
h: float
42-
w: float
43-
x: float
44-
y: float
45-
46-
47-
class BoundingBoxFrameCoordinatesDict(TypedDict):
48-
boundingBox: BoundingBoxDict
49-
50-
51-
class PointDict(TypedDict):
52-
x: float
53-
y: float
54-
55-
56-
class PointFrameCoordinatesDict(TypedDict):
57-
point: dict[str, PointDict] # Actually the key here is always '0', but no way to type that.
58-
59-
60-
class PointDict3D(PointDict):
61-
z: float
62-
63-
64-
class Point3DFrameCoordinatesDict(TypedDict):
65-
point: dict[str, PointDict3D] # Actually the key here is always '0', but no way to type that.
66-
67-
68-
class RotatableBoundingBoxDict(BoundingBoxDict):
69-
theta: float
70-
71-
72-
class RotatableBoundingBoxFrameCoordinatesDict(TypedDict):
73-
rotatableBoundingBox: RotatableBoundingBoxDict
74-
75-
76-
PolylineDict = Union[Dict[str, PointDict], list[PointDict], Dict[str, PointDict3D], list[PointDict3D]]
77-
78-
79-
class PolylineFrameCoordinatesDict(TypedDict):
80-
polyline: PolylineDict
81-
82-
83-
LegacyPolygonDict = Union[Dict[str, PointDict], list[PointDict]]
84-
PolygonDict = List[List[List[float]]] # Introduced to support complex polygons
85-
86-
87-
class PolygonFrameCoordinatesDictRequired(TypedDict):
88-
polygon: LegacyPolygonDict
89-
90-
91-
class PolygonFrameCoordinatesDict(PolygonFrameCoordinatesDictRequired, total=False):
92-
polygons: Optional[PolygonDict] # This was introduced to support complex polygons.
93-
9443

9544
@dataclass(frozen=True)
9645
class BoundingBoxCoordinates:

encord/objects/types.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,66 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, List, Literal, Optional, TypedDict, Union
3+
from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, TypedDict, Union
44

55
if TYPE_CHECKING:
66
from encord.objects import Shape
7-
from encord.objects.coordinates import (
8-
BoundingBoxDict,
9-
BoundingBoxFrameCoordinatesDict,
10-
LegacyPolygonDict,
11-
Point3DFrameCoordinatesDict,
12-
PointDict,
13-
PointDict3D,
14-
PointFrameCoordinatesDict,
15-
PolygonDict,
16-
PolygonFrameCoordinatesDict,
17-
PolylineDict,
18-
PolylineFrameCoordinatesDict,
19-
RotatableBoundingBoxDict,
20-
RotatableBoundingBoxFrameCoordinatesDict,
21-
)
7+
8+
""" Typed Dicts for Shape Coordinates """
9+
10+
11+
class BoundingBoxDict(TypedDict):
12+
h: float
13+
w: float
14+
x: float
15+
y: float
16+
17+
18+
class BoundingBoxFrameCoordinatesDict(TypedDict):
19+
boundingBox: BoundingBoxDict
20+
21+
22+
class PointDict(TypedDict):
23+
x: float
24+
y: float
25+
26+
27+
class PointFrameCoordinatesDict(TypedDict):
28+
point: dict[str, PointDict] # Actually the key here is always '0', but no way to type that.
29+
30+
31+
class PointDict3D(PointDict):
32+
z: float
33+
34+
35+
class Point3DFrameCoordinatesDict(TypedDict):
36+
point: dict[str, PointDict3D] # Actually the key here is always '0', but no way to type that.
37+
38+
39+
class RotatableBoundingBoxDict(BoundingBoxDict):
40+
theta: float
41+
42+
43+
class RotatableBoundingBoxFrameCoordinatesDict(TypedDict):
44+
rotatableBoundingBox: RotatableBoundingBoxDict
45+
46+
47+
PolylineDict = Union[Dict[str, PointDict], list[PointDict], Dict[str, PointDict3D], list[PointDict3D]]
48+
49+
50+
class PolylineFrameCoordinatesDict(TypedDict):
51+
polyline: PolylineDict
52+
53+
54+
LegacyPolygonDict = Union[Dict[str, PointDict], list[PointDict]]
55+
PolygonDict = List[List[List[float]]] # Introduced to support complex polygons
56+
57+
58+
class PolygonFrameCoordinatesDictRequired(TypedDict):
59+
polygon: LegacyPolygonDict
60+
61+
62+
class PolygonFrameCoordinatesDict(PolygonFrameCoordinatesDictRequired, total=False):
63+
polygons: Optional[PolygonDict] # This was introduced to support complex polygons.
2264

2365

2466
class AnswerDict(TypedDict):

0 commit comments

Comments
 (0)