Skip to content

refactor: move safety functions to safety.py#227

Merged
ktro2828 merged 1 commit into
mainfrom
refactor/sanity/safe-function
Nov 18, 2025
Merged

refactor: move safety functions to safety.py#227
ktro2828 merged 1 commit into
mainfrom
refactor/sanity/safe-function

Conversation

@ktro2828

Copy link
Copy Markdown
Collaborator

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.py module, 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:

  • Introduced new functions in t4_devkit/sanity/safety.py for safely loading schemas (load_schema_safe), metadata (load_metadata_safe), and Tier4 instances (load_tier4_safe), consolidating previously scattered logic.
  • Removed local @safe-decorated helper functions such as _safe_from_dict, _load_metadata_safe, and _load_tier4_safe from other modules, replacing their usage with imports from the new centralized safety.py utilities. [1] [2] [3]

Code simplification and import cleanup:

  • Updated imports in affected modules (e.g., context.py, base.py, tiv001.py) to use the new safe-loading utilities, removing unnecessary imports of safe and direct calls to load_metadata. [1] [2] [3]
  • Improved type-checking support and code clarity in safety.py by adding TYPE_CHECKING imports 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.

Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Copilot AI review requested due to automatic review settings November 18, 2025 05:20
@github-actions github-actions Bot added the refactor Refactoring code or increasing performance label Nov 18, 2025

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 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) in safety.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.

@github-actions

github-actions Bot commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
3896 3231 83% 50% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
t4_devkit/sanity/context.py 100% 🟢
t4_devkit/sanity/format/base.py 88% 🟢
t4_devkit/sanity/safety.py 100% 🟢
t4_devkit/sanity/tier4/tiv001.py 96% 🟢
TOTAL 96% 🟢

updated for commit: 0890731 by action🐍

@ktro2828 ktro2828 merged commit 0a65ade into main Nov 18, 2025
5 checks passed
@ktro2828 ktro2828 deleted the refactor/sanity/safe-function branch November 18, 2025 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Refactoring code or increasing performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants