Skip to content

Commit

Permalink
lint: enable FA100
Browse files Browse the repository at this point in the history
  • Loading branch information
tklockau committed Oct 28, 2024
1 parent a021152 commit abf238e
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 93 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ ignore = [

# to be removed later
"TID252",
"FA100",
]

[tool.mypy]
Expand Down
5 changes: 3 additions & 2 deletions raillabel_providerkit/_util/_attribute_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from enum import Enum

from ..exceptions import ValueDoesNotMatchTypeError
Expand All @@ -16,7 +17,7 @@ class AttributeType(Enum):
VEC = "vec"

@classmethod
def from_value(cls, attribute_value_class: t.Type) -> "AttributeType":
def from_value(cls, attribute_value_class: type) -> AttributeType:
"""Return AttributeType based on class of attribute value.
Parameters
Expand Down
6 changes: 3 additions & 3 deletions raillabel_providerkit/convert/convert.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

import raillabel

Expand All @@ -10,7 +10,7 @@
from .loader_classes import LoaderABC


def convert(data: dict, loader_class: t.Optional[t.Type[LoaderABC]] = None) -> raillabel.Scene:
def convert(data: dict, loader_class: type[LoaderABC] | None = None) -> raillabel.Scene:
"""Convert annotation data from provider formats into raillabel.
Parameters
Expand Down Expand Up @@ -38,7 +38,7 @@ def convert(data: dict, loader_class: t.Optional[t.Type[LoaderABC]] = None) -> r
return loader_class().load(data)


def _select_loader_class(data: dict) -> t.Type[LoaderABC]:
def _select_loader_class(data: dict) -> type[LoaderABC]:
loader_classes = [
cls
for cls in loader_classes_pkg.__dict__.values()
Expand Down
5 changes: 3 additions & 2 deletions raillabel_providerkit/convert/loader_classes/_loader_abc.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from abc import ABC, abstractmethod
from pathlib import Path

Expand All @@ -26,7 +27,7 @@ class LoaderABC(ABC):
"""

scene: raillabel.Scene
warnings: t.List[str]
warnings: list[str]
SCHEMA_PATH: Path

@abstractmethod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import json
import typing as t
from pathlib import Path

import jsonschema
Expand All @@ -26,7 +27,7 @@ class LoaderUnderstandAi(LoaderABC):
"""

scene: uai_format.Scene
warnings: t.List[str]
warnings: list[str]

SCHEMA_PATH: Path = (
Path(__file__).parent.parent.parent / "format" / "understand_ai_t4_schema.json"
Expand Down Expand Up @@ -84,7 +85,7 @@ def supports(self, data: dict) -> bool:
and "frames" in data
)

def validate_schema(self, data: dict) -> t.List[str]:
def validate_schema(self, data: dict) -> list[str]:
"""Check if the schema is correct."""
with self.SCHEMA_PATH.open() as file:
schema = json.load(file)
Expand Down
7 changes: 4 additions & 3 deletions raillabel_providerkit/format/understand_ai/_annotation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from abc import ABC, abstractmethod
from dataclasses import dataclass
from uuid import UUID
Expand All @@ -21,10 +22,10 @@ class _Annotation(ABC):

@classmethod
@abstractmethod
def fromdict(cls, data_dict: t.Dict) -> t.Type["_Annotation"]:
def fromdict(cls, data_dict: dict) -> type[_Annotation]:
raise NotImplementedError

def to_raillabel(self) -> t.Tuple[dict, str, str, dict]:
def to_raillabel(self) -> tuple[dict, str, str, dict]:
"""Convert to a raillabel compatible dict.
Returns
Expand Down
7 changes: 4 additions & 3 deletions raillabel_providerkit/format/understand_ai/bounding_box_2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from dataclasses import dataclass
from uuid import UUID

Expand Down Expand Up @@ -45,7 +46,7 @@ class BoundingBox2d(_Annotation):
OPENLABEL_ID = "bbox"

@classmethod
def fromdict(cls, data_dict: t.Dict) -> "BoundingBox2d":
def fromdict(cls, data_dict: dict) -> BoundingBox2d:
"""Generate a BoundingBox2d from a dictionary in the UAI format.
Parameters
Expand All @@ -71,7 +72,7 @@ def fromdict(cls, data_dict: t.Dict) -> "BoundingBox2d":
sensor=SensorReference.fromdict(data_dict["sensor"]),
)

def _val_to_raillabel(self) -> list:
def _val_to_raillabel(self) -> list[float]:
return [
(self.x_max + self.x_min) / 2,
(self.y_max + self.y_min) / 2,
Expand Down
7 changes: 4 additions & 3 deletions raillabel_providerkit/format/understand_ai/bounding_box_3d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from dataclasses import dataclass
from uuid import UUID

Expand Down Expand Up @@ -45,7 +46,7 @@ class BoundingBox3d(_Annotation):
OPENLABEL_ID = "cuboid"

@classmethod
def fromdict(cls, data_dict: t.Dict) -> "BoundingBox3d":
def fromdict(cls, data_dict: dict) -> BoundingBox3d:
"""Generate a BoundingBox3d from a dictionary in the UAI format.
Parameters
Expand All @@ -70,7 +71,7 @@ def fromdict(cls, data_dict: t.Dict) -> "BoundingBox3d":
sensor=SensorReference.fromdict(data_dict["sensor"]),
)

def _val_to_raillabel(self) -> list:
def _val_to_raillabel(self) -> list[float]:
return [
float(self.center.x),
float(self.center.y),
Expand Down
25 changes: 13 additions & 12 deletions raillabel_providerkit/format/understand_ai/coordinate_system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from dataclasses import dataclass

from ._translation import fetch_sensor_resolutions, fetch_sensor_type, translate_sensor_id
Expand Down Expand Up @@ -41,22 +42,22 @@ class CoordinateSystem:
uid: str
topic: str
frame_id: str
position: t.List[float]
rotation_quaternion: t.List[float]
rotation_matrix: t.List[float]
angle_axis_rotation: t.List[float]
homogeneous_transform: t.Optional[t.List[float]] = None
measured_position: t.Optional[t.List[float]] = None
camera_matrix: t.Optional[t.List[float]] = None
dist_coeffs: t.Optional[t.List[float]] = None
position: list[float]
rotation_quaternion: list[float]
rotation_matrix: list[float]
angle_axis_rotation: list[float]
homogeneous_transform: list[float] | None = None
measured_position: list[float] | None = None
camera_matrix: list[float] | None = None
dist_coeffs: list[float] | None = None

@property
def translated_uid(self) -> str:
"""Return uid translated to raillabel."""
return translate_sensor_id(self.uid)

@classmethod
def fromdict(cls, data_dict: dict) -> "CoordinateSystem":
def fromdict(cls, data_dict: dict) -> CoordinateSystem:
"""Generate a CoordinateSystem from a dictionary in the UAI format.
Parameters
Expand Down Expand Up @@ -84,7 +85,7 @@ def fromdict(cls, data_dict: dict) -> "CoordinateSystem":
dist_coeffs=data_dict.get("dist_coeffs"),
)

def to_raillabel(self) -> t.Tuple[dict, dict]:
def to_raillabel(self) -> tuple[dict, dict]:
"""Convert to a raillabel compatible dict.
Returns
Expand Down Expand Up @@ -117,7 +118,7 @@ def to_raillabel(self) -> t.Tuple[dict, dict]:

return stream_dict, coordinate_system_dict

def _stream_properties_to_raillabel(self, sensor_type: str) -> t.Optional[dict]:
def _stream_properties_to_raillabel(self, sensor_type: str) -> dict | None:
if sensor_type == "camera":
return {
"intrinsics_pinhole": {
Expand Down
21 changes: 11 additions & 10 deletions raillabel_providerkit/format/understand_ai/frame.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

import uuid
from dataclasses import dataclass
from decimal import Decimal
Expand Down Expand Up @@ -35,13 +36,13 @@ class Frame:

id: int
timestamp: Decimal
bounding_box_2ds: t.Dict[str, BoundingBox2d]
bounding_box_3ds: t.Dict[str, BoundingBox3d]
polygon_2ds: t.Dict[str, Polygon2d]
polyline_2ds: t.Dict[str, Polyline2d]
segmentation_3ds: t.Dict[str, Segmentation3d]
bounding_box_2ds: dict[str, BoundingBox2d]
bounding_box_3ds: dict[str, BoundingBox3d]
polygon_2ds: dict[str, Polygon2d]
polyline_2ds: dict[str, Polyline2d]
segmentation_3ds: dict[str, Segmentation3d]

_annotation_uids: t.Set[str] = None
_annotation_uids: set[str] = None

@property
def annotations(self) -> dict:
Expand Down Expand Up @@ -89,7 +90,7 @@ def translated_sensors(self) -> dict:
return {sensor.type: sensor for sensor in sensors_list}

@classmethod
def fromdict(cls, data_dict: dict) -> "Frame":
def fromdict(cls, data_dict: dict) -> Frame:
"""Generate a Frame from a dictionary in the UAI format.
Parameters
Expand Down Expand Up @@ -144,8 +145,8 @@ def to_raillabel(self) -> dict:

@classmethod
def _annotation_fromdict(
cls, data_dict: dict, annotation_class: t.Type[_Annotation]
) -> t.Dict[str, t.Type[_Annotation]]:
cls, data_dict: dict, annotation_class: type[_Annotation]
) -> dict[str, type[_Annotation]]:
annotations = {}
for annotation_dict in data_dict:
annotation_dict["id"] = cls._check_duplicate_annotation_uid(annotation_dict["id"])
Expand Down
11 changes: 6 additions & 5 deletions raillabel_providerkit/format/understand_ai/polygon_2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from dataclasses import dataclass
from uuid import UUID

Expand Down Expand Up @@ -31,12 +32,12 @@ class Polygon2d(_Annotation):
"""

points: t.List[t.Tuple[float, float]]
points: list[tuple[float, float]]

OPENLABEL_ID = "poly2d"

@classmethod
def fromdict(cls, data_dict: t.Dict) -> "Polygon2d":
def fromdict(cls, data_dict: dict) -> Polygon2d:
"""Generate a Polygon2d from a dictionary in the UAI format.
Parameters
Expand All @@ -59,7 +60,7 @@ def fromdict(cls, data_dict: t.Dict) -> "Polygon2d":
points=[(p[0], p[1]) for p in data_dict["geometry"]["points"]],
)

def to_raillabel(self) -> t.Tuple[dict, str, str, dict]:
def to_raillabel(self) -> tuple[dict, str, str, dict]:
"""Convert to a raillabel compatible dict.
Returns
Expand All @@ -80,5 +81,5 @@ def to_raillabel(self) -> t.Tuple[dict, str, str, dict]:

return polygon

def _val_to_raillabel(self) -> t.List[float]:
def _val_to_raillabel(self) -> list[float]:
return [coordinate for point in self.points for coordinate in point]
11 changes: 6 additions & 5 deletions raillabel_providerkit/format/understand_ai/polyline_2d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright DB Netz AG and contributors
# SPDX-License-Identifier: Apache-2.0

import typing as t
from __future__ import annotations

from dataclasses import dataclass
from uuid import UUID

Expand Down Expand Up @@ -31,12 +32,12 @@ class Polyline2d(_Annotation):
"""

points: t.List[t.Tuple[float, float]]
points: list[tuple[float, float]]

OPENLABEL_ID = "poly2d"

@classmethod
def fromdict(cls, data_dict: t.Dict) -> "Polyline2d":
def fromdict(cls, data_dict: dict) -> Polyline2d:
"""Generate a Polyline2d from a dictionary in the UAI format.
Parameters
Expand All @@ -59,7 +60,7 @@ def fromdict(cls, data_dict: t.Dict) -> "Polyline2d":
points=[(p[0], p[1]) for p in data_dict["geometry"]["points"]],
)

def to_raillabel(self) -> t.Tuple[dict, str, str, dict]:
def to_raillabel(self) -> tuple[dict, str, str, dict]:
"""Convert to a raillabel compatible dict.
Returns
Expand All @@ -80,5 +81,5 @@ def to_raillabel(self) -> t.Tuple[dict, str, str, dict]:

return polyline

def _val_to_raillabel(self) -> t.List[float]:
def _val_to_raillabel(self) -> list[float]:
return [coordinate for point in self.points for coordinate in point]
Loading

0 comments on commit abf238e

Please sign in to comment.