diff --git a/pyproject.toml b/pyproject.toml index 154617e..9dc8a3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -84,7 +84,6 @@ ignore = [ # to be removed later "TID252", - "FA100", ] [tool.mypy] diff --git a/raillabel_providerkit/_util/_attribute_type.py b/raillabel_providerkit/_util/_attribute_type.py index 87fb5b7..29909f3 100644 --- a/raillabel_providerkit/_util/_attribute_type.py +++ b/raillabel_providerkit/_util/_attribute_type.py @@ -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 @@ -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 diff --git a/raillabel_providerkit/convert/convert.py b/raillabel_providerkit/convert/convert.py index 161578b..5b59096 100644 --- a/raillabel_providerkit/convert/convert.py +++ b/raillabel_providerkit/convert/convert.py @@ -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 @@ -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 @@ -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() diff --git a/raillabel_providerkit/convert/loader_classes/_loader_abc.py b/raillabel_providerkit/convert/loader_classes/_loader_abc.py index a83ce81..ab718e9 100644 --- a/raillabel_providerkit/convert/loader_classes/_loader_abc.py +++ b/raillabel_providerkit/convert/loader_classes/_loader_abc.py @@ -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 @@ -26,7 +27,7 @@ class LoaderABC(ABC): """ scene: raillabel.Scene - warnings: t.List[str] + warnings: list[str] SCHEMA_PATH: Path @abstractmethod diff --git a/raillabel_providerkit/convert/loader_classes/loader_understand_ai.py b/raillabel_providerkit/convert/loader_classes/loader_understand_ai.py index edc21e2..ba1c1fa 100644 --- a/raillabel_providerkit/convert/loader_classes/loader_understand_ai.py +++ b/raillabel_providerkit/convert/loader_classes/loader_understand_ai.py @@ -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 @@ -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" @@ -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) diff --git a/raillabel_providerkit/format/understand_ai/_annotation.py b/raillabel_providerkit/format/understand_ai/_annotation.py index af94cba..d8d2749 100644 --- a/raillabel_providerkit/format/understand_ai/_annotation.py +++ b/raillabel_providerkit/format/understand_ai/_annotation.py @@ -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 @@ -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 diff --git a/raillabel_providerkit/format/understand_ai/bounding_box_2d.py b/raillabel_providerkit/format/understand_ai/bounding_box_2d.py index da780b4..2bb7269 100644 --- a/raillabel_providerkit/format/understand_ai/bounding_box_2d.py +++ b/raillabel_providerkit/format/understand_ai/bounding_box_2d.py @@ -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 @@ -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 @@ -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, diff --git a/raillabel_providerkit/format/understand_ai/bounding_box_3d.py b/raillabel_providerkit/format/understand_ai/bounding_box_3d.py index bd1043a..0573248 100644 --- a/raillabel_providerkit/format/understand_ai/bounding_box_3d.py +++ b/raillabel_providerkit/format/understand_ai/bounding_box_3d.py @@ -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 @@ -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 @@ -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), diff --git a/raillabel_providerkit/format/understand_ai/coordinate_system.py b/raillabel_providerkit/format/understand_ai/coordinate_system.py index c388682..f0f39b2 100644 --- a/raillabel_providerkit/format/understand_ai/coordinate_system.py +++ b/raillabel_providerkit/format/understand_ai/coordinate_system.py @@ -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 @@ -41,14 +42,14 @@ 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: @@ -56,7 +57,7 @@ def translated_uid(self) -> str: 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 @@ -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 @@ -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": { diff --git a/raillabel_providerkit/format/understand_ai/frame.py b/raillabel_providerkit/format/understand_ai/frame.py index 27ab5aa..cb3a77a 100644 --- a/raillabel_providerkit/format/understand_ai/frame.py +++ b/raillabel_providerkit/format/understand_ai/frame.py @@ -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 @@ -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: @@ -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 @@ -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"]) diff --git a/raillabel_providerkit/format/understand_ai/polygon_2d.py b/raillabel_providerkit/format/understand_ai/polygon_2d.py index 4179b35..1027e3a 100644 --- a/raillabel_providerkit/format/understand_ai/polygon_2d.py +++ b/raillabel_providerkit/format/understand_ai/polygon_2d.py @@ -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 @@ -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 @@ -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 @@ -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] diff --git a/raillabel_providerkit/format/understand_ai/polyline_2d.py b/raillabel_providerkit/format/understand_ai/polyline_2d.py index 5a292fa..3e753af 100644 --- a/raillabel_providerkit/format/understand_ai/polyline_2d.py +++ b/raillabel_providerkit/format/understand_ai/polyline_2d.py @@ -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 @@ -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 @@ -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 @@ -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] diff --git a/raillabel_providerkit/format/understand_ai/scene.py b/raillabel_providerkit/format/understand_ai/scene.py index a96bc37..035ef72 100644 --- a/raillabel_providerkit/format/understand_ai/scene.py +++ b/raillabel_providerkit/format/understand_ai/scene.py @@ -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 ..._util._warning import _warning @@ -25,11 +26,11 @@ class Scene: """ metadata: Metadata - coordinate_systems: t.Dict[str, CoordinateSystem] - frames: t.Dict[int, Frame] + coordinate_systems: dict[str, CoordinateSystem] + frames: dict[int, Frame] @classmethod - def fromdict(cls, data_dict: dict) -> "Scene": + def fromdict(cls, data_dict: dict) -> Scene: """Generate a Scene from a dictionary in the UAI format. Parameters @@ -69,7 +70,7 @@ def to_raillabel(self) -> dict: } @classmethod - def _coordinate_systems_fromdict(cls, data_dict: t.List[dict]) -> t.Dict[str, CoordinateSystem]: + def _coordinate_systems_fromdict(cls, data_dict: list[dict]) -> dict[str, CoordinateSystem]: coordinate_systems = {} for cs in data_dict: coordinate_systems[cs["coordinate_system_id"]] = CoordinateSystem.fromdict(cs) @@ -77,7 +78,7 @@ def _coordinate_systems_fromdict(cls, data_dict: t.List[dict]) -> t.Dict[str, Co return coordinate_systems @classmethod - def _frames_fromdict(cls, data_dict: t.List[dict]) -> t.Dict[int, Frame]: + def _frames_fromdict(cls, data_dict: list[dict]) -> dict[int, Frame]: frames = {} for frame in data_dict: frame_id = int(frame["frameId"]) diff --git a/raillabel_providerkit/format/understand_ai/segmentation_3d.py b/raillabel_providerkit/format/understand_ai/segmentation_3d.py index bb622dc..9bb54e9 100644 --- a/raillabel_providerkit/format/understand_ai/segmentation_3d.py +++ b/raillabel_providerkit/format/understand_ai/segmentation_3d.py @@ -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 @@ -33,13 +34,13 @@ class Segmentation3d(_Annotation): """ - associated_points: t.List[int] + associated_points: list[int] number_of_points: int OPENLABEL_ID = "vec" @classmethod - def fromdict(cls, data_dict: t.Dict) -> "Segmentation3d": + def fromdict(cls, data_dict: dict) -> Segmentation3d: """Generate a Segmentation3d from a dictionary in the UAI format. Parameters diff --git a/raillabel_providerkit/format/understand_ai/sensor_reference.py b/raillabel_providerkit/format/understand_ai/sensor_reference.py index c8bc37c..8517509 100644 --- a/raillabel_providerkit/format/understand_ai/sensor_reference.py +++ b/raillabel_providerkit/format/understand_ai/sensor_reference.py @@ -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 decimal import Decimal @@ -26,7 +27,7 @@ class SensorReference: timestamp: Decimal @classmethod - def fromdict(cls, data_dict: dict) -> "SensorReference": + def fromdict(cls, data_dict: dict) -> SensorReference: """Generate a SensorReference from a dictionary in the UAI format. Parameters @@ -44,7 +45,7 @@ def fromdict(cls, data_dict: dict) -> "SensorReference": type=data_dict["type"], uri=data_dict["uri"], timestamp=Decimal(data_dict["timestamp"]) ) - def to_raillabel(self) -> t.Tuple[str, dict]: + def to_raillabel(self) -> tuple[str, dict]: """Convert to a raillabel compatible dict. Returns diff --git a/raillabel_providerkit/validation/validate.py b/raillabel_providerkit/validation/validate.py index b38da69..e4f1403 100644 --- a/raillabel_providerkit/validation/validate.py +++ b/raillabel_providerkit/validation/validate.py @@ -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 pathlib import Path import raillabel @@ -9,7 +10,7 @@ from . import validate_onthology -def validate(scene: raillabel.Scene, onthology: t.Union[dict, Path]) -> t.List[str]: +def validate(scene: raillabel.Scene, onthology: dict | Path) -> list[str]: """Validate a scene based on the Deutsche Bahn Requirements. Parameters diff --git a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py index 3e819a1..129bb7f 100644 --- a/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py +++ b/raillabel_providerkit/validation/validate_empty_frames/validate_empty_frames.py @@ -1,12 +1,12 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 -from typing import List +from __future__ import annotations import raillabel -def validate_empty_frames(scene: raillabel.Scene) -> List[str]: +def validate_empty_frames(scene: raillabel.Scene) -> list[str]: """Validate whether all frames of a scene have at least one annotation. Parameters @@ -21,7 +21,7 @@ def validate_empty_frames(scene: raillabel.Scene) -> List[str]: errors present. """ - errors: List[str] = [] + errors: list[str] = [] for frame_uid, frame in scene.frames.items(): if _is_frame_empty(frame): diff --git a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_object_classes.py b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_object_classes.py index e772256..db7969a 100644 --- a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_object_classes.py +++ b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_object_classes.py @@ -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 import raillabel @@ -12,11 +13,11 @@ @dataclass class _ObjectClass: - attributes: t.Dict[str, t.Type[_Attribute]] - sensor_types: t.Dict[raillabel.format.SensorType, _SensorType] + attributes: dict[str, type[_Attribute]] + sensor_types: dict[raillabel.format.SensorType, _SensorType] @classmethod - def fromdict(cls, data_dict: dict) -> "_ObjectClass": + def fromdict(cls, data_dict: dict) -> _ObjectClass: if "attributes" not in data_dict: data_dict["attributes"] = {} @@ -31,7 +32,7 @@ def fromdict(cls, data_dict: dict) -> "_ObjectClass": sensor_types=cls._sensor_types_fromdict(data_dict["sensor_types"]), ) - def check(self, annotation: t.Type[raillabel.format._ObjectAnnotation]) -> t.List[str]: + def check(self, annotation: type[raillabel.format._ObjectAnnotation]) -> list[str]: errors = [] errors.extend(self._check_undefined_attributes(annotation)) @@ -41,7 +42,7 @@ def check(self, annotation: t.Type[raillabel.format._ObjectAnnotation]) -> t.Lis return errors @classmethod - def _attribute_fromdict(cls, attribute: dict or str) -> t.Type[_Attribute]: + def _attribute_fromdict(cls, attribute: dict or str) -> type[_Attribute]: for attribute_class in attribute_classes(): if attribute_class.supports(attribute): return attribute_class.fromdict(attribute) @@ -49,15 +50,15 @@ def _attribute_fromdict(cls, attribute: dict or str) -> t.Type[_Attribute]: raise ValueError @classmethod - def _sensor_types_fromdict(cls, sensor_types_dict: dict) -> t.Dict[str, _SensorType]: + def _sensor_types_fromdict(cls, sensor_types_dict: dict) -> dict[str, _SensorType]: return { raillabel.format.SensorType(type_id): _SensorType.fromdict(sensor_type_dict) for type_id, sensor_type_dict in sensor_types_dict.items() } def _check_undefined_attributes( - self, annotation: t.Type[raillabel.format._ObjectAnnotation] - ) -> t.List[str]: + self, annotation: type[raillabel.format._ObjectAnnotation] + ) -> list[str]: return [ f"Undefined attribute '{attr_name}' in annotation {annotation.uid}." for attr_name in annotation.attributes @@ -65,8 +66,8 @@ def _check_undefined_attributes( ] def _check_missing_attributes( - self, annotation: t.Type[raillabel.format._ObjectAnnotation] - ) -> t.List[str]: + self, annotation: type[raillabel.format._ObjectAnnotation] + ) -> list[str]: return [ f"Missing attribute '{attr_name}' in annotation {annotation.uid}." for attr_name in self._compile_applicable_attributes(annotation) @@ -74,8 +75,8 @@ def _check_missing_attributes( ] def _check_false_attribute_type( - self, annotation: t.Type[raillabel.format._ObjectAnnotation] - ) -> t.List[str]: + self, annotation: type[raillabel.format._ObjectAnnotation] + ) -> list[str]: errors = [] applicable_attributes = self._compile_applicable_attributes(annotation) @@ -90,8 +91,8 @@ def _check_false_attribute_type( return errors def _compile_applicable_attributes( - self, annotation: t.Type[raillabel.format._ObjectAnnotation] - ) -> t.Dict[str, t.Type[_Attribute]]: + self, annotation: type[raillabel.format._ObjectAnnotation] + ) -> dict[str, type[_Attribute]]: applicable_attributes = self.attributes if annotation.sensor.type in self.sensor_types: diff --git a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_onthology.py b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_onthology.py index c16ea67..73201d3 100644 --- a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_onthology.py +++ b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_onthology.py @@ -1,6 +1,8 @@ # Copyright DB Netz AG and contributors # SPDX-License-Identifier: Apache-2.0 +from __future__ import annotations + import typing as t from dataclasses import dataclass @@ -11,16 +13,16 @@ @dataclass class _Onthology: - classes: t.Dict[str, _ObjectClass] + classes: dict[str, _ObjectClass] errors: t.ClassVar = [] @classmethod - def fromdict(cls, data_dict: dict) -> "_Onthology": + def fromdict(cls, data_dict: dict) -> _Onthology: return _Onthology( {class_id: _ObjectClass.fromdict(class_) for class_id, class_ in data_dict.items()} ) - def check(self, scene: raillabel.Scene) -> t.List[str]: + def check(self, scene: raillabel.Scene) -> list[str]: self.errors = [] self._check_class_validity(scene) @@ -30,7 +32,7 @@ def check(self, scene: raillabel.Scene) -> t.List[str]: return self.errors - def _check_class_validity(self, scene: raillabel.Scene) -> t.List[str]: + def _check_class_validity(self, scene: raillabel.Scene) -> list[str]: object_classes_in_scene = [obj.type for obj in scene.objects.values()] for object_class in object_classes_in_scene: @@ -39,7 +41,7 @@ def _check_class_validity(self, scene: raillabel.Scene) -> t.List[str]: def _compile_annotations( self, scene: raillabel.Scene - ) -> t.List[t.Type[raillabel.format._ObjectAnnotation]]: + ) -> list[type[raillabel.format._ObjectAnnotation]]: annotations = [] for frame in scene.frames.values(): annotations.extend(list(frame.annotations.values())) diff --git a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_sensor_type.py b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_sensor_type.py index d0a30d1..1c29cae 100644 --- a/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_sensor_type.py +++ b/raillabel_providerkit/validation/validate_onthology/_onthology_classes/_sensor_type.py @@ -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 ._attributes._attribute_abc import _Attribute, attribute_classes @@ -9,10 +10,10 @@ @dataclass class _SensorType: - attributes: t.Dict[str, t.Type[_Attribute]] + attributes: dict[str, type[_Attribute]] @classmethod - def fromdict(cls, data_dict: dict) -> "_SensorType": + def fromdict(cls, data_dict: dict) -> _SensorType: if "attributes" not in data_dict: data_dict["attributes"] = {} @@ -24,7 +25,7 @@ def fromdict(cls, data_dict: dict) -> "_SensorType": ) @classmethod - def _attribute_fromdict(cls, attribute: dict or str) -> t.Type[_Attribute]: + def _attribute_fromdict(cls, attribute: dict | str) -> type[_Attribute]: for attribute_class in attribute_classes(): if attribute_class.supports(attribute): return attribute_class.fromdict(attribute)