refactor: move safety functions to safety.py#227
Merged
Conversation
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the codebase by consolidating scattered safe-loading utility functions into a centralized safety.py module. The changes eliminate code duplication and standardize error handling for loading metadata, schemas, and Tier4 instances across the sanity checking system.
Key Changes:
- Created centralized safe-loading functions (
load_schema_safe,load_metadata_safe,load_tier4_safe) insafety.py - Removed duplicate local implementations of safe-loading helpers from multiple modules
- Updated imports across affected modules to use the new centralized utilities
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| t4_devkit/sanity/safety.py | Added three new safe-loading utility functions with proper type hints and docstrings |
| t4_devkit/sanity/tier4/tiv001.py | Replaced local _load_tier4_safe with centralized load_tier4_safe import |
| t4_devkit/sanity/format/base.py | Replaced local _safe_from_dict with centralized load_schema_safe import |
| t4_devkit/sanity/context.py | Replaced local _load_metadata_safe with centralized load_metadata_safe import |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
This pull request refactors and centralizes the codebase's safe-loading logic for metadata, schemas, and Tier4 instances. It moves previously duplicated or scattered safe-loading functions into a new
safety.pymodule, standardizing error handling and simplifying imports throughout the codebase. The main logic and error handling for loading metadata, schemas, and Tier4 instances are now consistently handled through dedicated utility functions.Centralization and refactoring of safe-loading utilities:
t4_devkit/sanity/safety.pyfor safely loading schemas (load_schema_safe), metadata (load_metadata_safe), and Tier4 instances (load_tier4_safe), consolidating previously scattered logic.@safe-decorated helper functions such as_safe_from_dict,_load_metadata_safe, and_load_tier4_safefrom other modules, replacing their usage with imports from the new centralizedsafety.pyutilities. [1] [2] [3]Code simplification and import cleanup:
context.py,base.py,tiv001.py) to use the new safe-loading utilities, removing unnecessary imports ofsafeand direct calls toload_metadata. [1] [2] [3]safety.pyby addingTYPE_CHECKINGimports and docstrings for the new utility functions. [1] [2]These changes improve maintainability by reducing code duplication and ensuring consistent error handling across the codebase.