Skip to content

refactor(typing): add comprehensive types and their aliases#171

Merged
ktro2828 merged 11 commits into
mainfrom
refactor/typing
Aug 21, 2025
Merged

refactor(typing): add comprehensive types and their aliases#171
ktro2828 merged 11 commits into
mainfrom
refactor/typing

Conversation

@ktro2828

@ktro2828 ktro2828 commented Aug 20, 2025

Copy link
Copy Markdown
Collaborator

What

This PR adds comprehensive types, which validates the input when it is constructed.

Type with Validation

For example, t4_devkit.typing.Vector3 validates the input array whether the shape of the array is 3:

from t4_devkit.typing import Vector3

>>> v = Vector3(1, 2, 3) # OK
>>> v = Vector3([1, 2, 3]) # OK
>>> v = Vector3(1, 2, 3, 4) # ValueError: Input array must be 3-elements

Type Aliases

In typing.aliases, comprehensive type aliases are defined, and they allow developer to add type hints easily:

def some_func(position: list[float] | tuple[float, float, float] | ArrayLike | Vector3):
    ...

# Instead of the above
def some_func(position: Vector3Like):
   ...

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Copilot AI review requested due to automatic review settings August 20, 2025 10:36
@github-actions github-actions Bot added ci Continuous Integration (CI) processes and testing refactor Refactoring code or increasing performance labels Aug 20, 2025
@github-actions

github-actions Bot commented Aug 20, 2025

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ❌

Overall Coverage

Lines Covered Coverage Threshold Status
2399 1660 69% 50% 🟢

New Files

File Coverage Status
t4_devkit/typing/init.py 100% 🟢
t4_devkit/typing/aliases.py 100% 🟢
t4_devkit/typing/camera.py 90% 🟢
t4_devkit/typing/matrix.py 100% 🟢
t4_devkit/typing/quaternion.py 100% 🟢
t4_devkit/typing/roi.py 95% 🟢
t4_devkit/typing/trajectory.py 93% 🟢
t4_devkit/typing/vector.py 92% 🟢
TOTAL 96% 🟢

Modified Files

File Coverage Status
t4_devkit/common/converter.py 100% 🟢
t4_devkit/common/geometry.py 94% 🟢
t4_devkit/common/timestamp.py 100% 🟢
t4_devkit/dataclass/init.py 100% 🟢
t4_devkit/dataclass/box.py 83% 🟢
t4_devkit/dataclass/shape.py 97% 🟢
t4_devkit/dataclass/trajectory.py 91% 🟢
t4_devkit/dataclass/transform.py 76% 🔴
t4_devkit/schema/tables/calibrated_sensor.py 100% 🟢
t4_devkit/schema/tables/ego_pose.py 100% 🟢
t4_devkit/schema/tables/object_ann.py 86% 🟢
t4_devkit/schema/tables/sample_annotation.py 100% 🟢
t4_devkit/schema/tables/surface_ann.py 73% 🔴
t4_devkit/tier4.py 17% 🔴
t4_devkit/viewer/color.py 100% 🟢
t4_devkit/viewer/geography.py 50% 🔴
t4_devkit/viewer/record/box.py 92% 🟢
t4_devkit/viewer/viewer.py 83% 🟢
TOTAL 86% 🔴

updated for commit: e76f936 by action🐍

This comment was marked as outdated.

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 requested a review from Copilot August 20, 2025 10:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces comprehensive type validation and type aliases to the T4 dataset toolkit. It replaces the existing monolithic typing.py module with a structured typing package containing specialized classes for vectors, matrices, quaternions, and camera parameters with built-in validation.

Key changes include:

  • Addition of validated type classes (Vector2, Vector3, Vector6, Matrix3x3, Matrix4x4, Quaternion, Roi, Trajectory, CameraIntrinsic, CameraDistortion)
  • Comprehensive type aliases in typing.aliases for flexible input handling
  • Removal of old validation system in favor of type constructors
  • Extensive test coverage for all new typing components

Reviewed Changes

Copilot reviewed 39 out of 39 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
t4_devkit/typing/__init__.py Main typing module exports with numpy array type definitions
t4_devkit/typing/vector.py BaseVector class and Vector2/3/6 implementations with validation
t4_devkit/typing/matrix.py Matrix3x3 and Matrix4x4 classes with shape validation
t4_devkit/typing/quaternion.py Quaternion wrapper around PyQuaternion
t4_devkit/typing/roi.py ROI class with geometric property methods
t4_devkit/typing/trajectory.py Trajectory class with 3D shape validation
t4_devkit/typing/camera.py Camera intrinsic and distortion parameter classes
t4_devkit/typing/aliases.py Comprehensive type aliases for flexible input handling
tests/typing/ Extensive test suite covering all typing components
Various schema/dataclass files Updated to use new typing system
Comments suppressed due to low confidence (1)

tests/typing/test_vector.py:108

  • The test case test_invalid_2d_array on line 108 is checking for ValueError with a specific message, but the actual error would likely occur during numpy array conversion before reaching the Trajectory validation. This test might not be testing the intended validation path.
        assert mean == 3.5

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread tests/viewer/test_viewer.py
Comment thread t4_devkit/typing/vector.py Outdated
Comment thread t4_devkit/typing/roi.py
Comment thread t4_devkit/typing/trajectory.py
Comment thread t4_devkit/typing/camera.py
Comment thread t4_devkit/typing/aliases.py Outdated
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
@ktro2828 ktro2828 merged commit c16a7a2 into main Aug 21, 2025
4 of 5 checks passed
@ktro2828 ktro2828 deleted the refactor/typing branch August 21, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continuous Integration (CI) processes and testing refactor Refactoring code or increasing performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants