refactor: add EntityPath enum#265
Conversation
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
35d1f71 to
3994d01
Compare
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
3994d01 to
4dbd006
Compare
There was a problem hiding this comment.
Pull request overview
Refactors viewer entity path handling by introducing a centralized EntityPath enum and migrating existing hardcoded path strings to enum members.
Changes:
- Added
EntityPathenum and updatedformat_entityto acceptstr | EntityPath. - Replaced string-based entity paths across viewer/builder/helper modules with enum usage.
- Updated viewer tests to cover enum-based entity path formatting.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/viewer/test_viewer.py | Extends format_entity tests to cover EntityPath inputs. |
| t4_devkit/viewer/viewer.py | Migrates viewer logging/timeline/entity path construction to EntityPath. |
| t4_devkit/viewer/config.py | Introduces EntityPath and updates ViewerConfig typing + format_entity signature/docs. |
| t4_devkit/viewer/builder.py | Switches blueprint view origins to use EntityPath. |
| t4_devkit/helper/rendering.py | Updates helper rendering entity roots to use EntityPath. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| render_ways(parser, root_entity) | ||
|
|
||
| render_geographic_borders(parser, f"{self.config.geocoordinate_entity}/vector_map") | ||
| render_geographic_borders(parser, f"{EntityPath.GEOCOORDINATE}/{EntityPath.VECTOR_MAP}") |
There was a problem hiding this comment.
EntityPath is an Enum; interpolating it via an f-string can yield the enum's name (e.g., EntityPath.GEOCOORDINATE) rather than the intended value (geocoordinate), depending on Python/Enum behavior. Build this path with format_entity(EntityPath.GEOCOORDINATE, EntityPath.VECTOR_MAP) or use .value for both enum members to guarantee the correct string.
| render_geographic_borders(parser, f"{EntityPath.GEOCOORDINATE}/{EntityPath.VECTOR_MAP}") | |
| render_geographic_borders(parser, format_entity(EntityPath.GEOCOORDINATE, EntityPath.VECTOR_MAP)) |
| if color_mode == PointCloudColorMode.SEGMENTATION: | ||
| if not isinstance(pointcloud, SegmentationPointCloud): | ||
| raise TypeError( |
There was a problem hiding this comment.
SegmentationPointCloud is referenced at runtime in an isinstance check, but it is no longer imported in the shown TYPE_CHECKING block (and there is no runtime import in this diff). If there isn't another runtime import elsewhere in this module, this will raise NameError. Ensure SegmentationPointCloud is imported at runtime (not under TYPE_CHECKING).
|
|
||
|
|
There was a problem hiding this comment.
To make EntityPath reliably behave like a plain string across all call sites (logging, serialization, f-strings, etc.), consider switching to StrEnum (if the supported Python version allows it) or explicitly overriding __str__/__format__ to return self.value. This avoids subtle issues where an enum may stringify to EntityPath.MAP instead of map.
| def __str__(self) -> str: | |
| """Return the underlying string value of the entity path.""" | |
| return self.value | |
| def __format__(self, format_spec: str) -> str: | |
| """Format the underlying string value of the entity path.""" | |
| return format(self.value, format_spec) |
…to EntityPath enumerations Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
4dbd006 to
42846bf
Compare
What
This pull request refactors how entity paths are managed throughout the viewer module by introducing a new
EntityPathenum. This change replaces hardcoded string constants and class variables with strongly-typed enum members, improving code maintainability, readability, and reducing the risk of typos. The update is applied consistently across helper, builder, config, and viewer files, and ensures that all entity path references use the new enum. Additionally, theformat_entityfunction is updated to accept both strings andEntityPathmembers, and several type annotations are improved for clarity.Entity Path Refactoring:
EntityPathenum int4_devkit/viewer/config.pyto centralize and standardize entity path definitions, replacing previous string constants and class variables. [1] [2]"map","map/base_link", etc.) in files such asrendering.py,builder.py, andviewer.pyto use the newEntityPathenum members. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21]Function and Type Improvements:
format_entityto accept bothstrandEntityPatharguments, and updated its docstring and usage examples accordingly. [1] [2]viewer.py, making the code clearer and more robust. [1] [2] [3]Test and Import Updates:
EntityPathenum where appropriate.These changes modernize the codebase, making it easier to maintain and less error-prone when dealing with entity paths.