Skip to content

Comments

refactor: enhance type safety and API consistency#24

Merged
CodeWithBotinaOficial merged 3 commits intodevelopfrom
feature/conversion-units
Dec 5, 2025
Merged

refactor: enhance type safety and API consistency#24
CodeWithBotinaOficial merged 3 commits intodevelopfrom
feature/conversion-units

Conversation

@CodeWithBotinaOficial
Copy link
Member

This commit introduces a comprehensive refactoring across multiple modules to improve code quality, maintainability, and type safety.

Key changes include:

  • Standardized NumPy type hints from specific dtypes (e.g., NDArray[np.uint8]) to the more flexible NDArray[Any] in high-level interfaces like CameraController and MainWindow. This accommodates the various data types passed between the GUI, processing, and analysis layers.
  • Replaced matplotlib.axes.Axes with the more specific mpl_toolkits.mplot3d.Axes3D in the 3D plotting module for better type checking and clarity.
  • Refactored the ImagePreprocessor and its strategies to consistently implement the IPreprocessor interface, improving adherence to the Strategy pattern.
  • Removed redundant type casts and unused Any type hints in CanvasPanel and other GUI components.
  • Updated pyproject.toml with stricter mypy configurations to enforce these improvements.
  • Corrected minor inconsistencies in function signatures and variable naming throughout the codebase.

This commit introduces a comprehensive refactoring across multiple modules to improve code quality, maintainability, and type safety.

Key changes include:
- Standardized NumPy type hints from specific dtypes (e.g., `NDArray[np.uint8]`) to the more flexible `NDArray[Any]` in high-level interfaces like `CameraController` and `MainWindow`. This accommodates the various data types passed between the GUI, processing, and analysis layers.
- Replaced `matplotlib.axes.Axes` with the more specific `mpl_toolkits.mplot3d.Axes3D` in the 3D plotting module for better type checking and clarity.
- Refactored the `ImagePreprocessor` and its strategies to consistently implement the `IPreprocessor` interface, improving adherence to the Strategy pattern.
- Removed redundant type casts and unused `Any` type hints in `CanvasPanel` and other GUI components.
- Updated `pyproject.toml` with stricter `mypy` configurations to enforce these improvements.
- Corrected minor inconsistencies in function signatures and variable naming throughout the codebase.
Migrates all static analysis settings from the standalone `mypy.ini` file into `pyproject.toml` under the `[tool.mypy]` section. This centralizes project configuration and simplifies the toolchain.

- Deletes `mypy.ini`.
- Adds a comprehensive `[tool.mypy]` configuration to `pyproject.toml`, enabling stricter checks like `disallow_untyped_defs` and `no_implicit_optional`.
- Configures `mypy` to ignore missing imports for third-party libraries like `matplotlib`, `numpy`, and `cv2` to reduce noise.
- Updates the CI workflow in `tests.yml` to correctly run `mypy` without referencing the old config file.
- Refactors type hints and adds explicit `cast` calls across the GUI and visualization modules (`gui_module`, `plot3d`, `visualizers`) to resolve errors surfaced by the new, stricter type-checking rules.
- Corrects a runtime bug in `visualizers.py` where `cv2.fillConvexPoly` was passed an integer for color instead of a tuple.
Introduces a new GitHub Actions workflow, `ci-github-actions.yml`, specifically for running quality checks (linting and type checking) across multiple operating systems.

This change separates the quality assurance steps from the testing pipeline (`tests.yml`), allowing for more granular and focused CI jobs.

Key features of the new workflow:
- Runs on both `ubuntu-latest` and `windows-latest` to ensure cross-platform compatibility.
- Uses `black --check` and `flake8` for code formatting and style enforcement.
- Executes `mypy` for static type analysis.
- Modernizes dependency installation by using `pip install -e '.[dev]'`, which installs dependencies directly from `pyproject.toml`.
- Sets `PYTHONPATH` correctly to ensure linters can find the source modules.
@CodeWithBotinaOficial CodeWithBotinaOficial merged commit e6829c6 into develop Dec 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant