Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔧 mypy Type Check tiatoolbox/models #912

Merged
merged 20 commits into from
Apr 3, 2025
Merged

Conversation

Jiaqi-Lv
Copy link
Contributor

@Jiaqi-Lv Jiaqi-Lv commented Feb 14, 2025

This pull request fixed typing in the following files:

  • tiatoolbox/models/__init__.py
  • tiatoolbox/models/models_abc.py
  • tiatoolbox/models/architecture/__init__.py
  • tiatoolbox/models/architecture/utils.py

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.93%. Comparing base (1f2282b) to head (d0cff65).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop     #912   +/-   ##
========================================
  Coverage    99.93%   99.93%           
========================================
  Files           71       71           
  Lines         8836     8848   +12     
  Branches      1153     1154    +1     
========================================
+ Hits          8830     8842   +12     
  Misses           3        3           
  Partials         3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jiaqi-Lv Jiaqi-Lv self-assigned this Feb 21, 2025
@shaneahmed shaneahmed changed the title Dev mypy type check tiatoolbox/models 🔧 mypy Type Check tiatoolbox/models Feb 24, 2025
@shaneahmed shaneahmed added this to the Release v1.7.0 milestone Mar 7, 2025
@shaneahmed shaneahmed added the dev tools Changes/Updates in Development tools label Mar 21, 2025
@Jiaqi-Lv Jiaqi-Lv marked this pull request as ready for review March 28, 2025 13:43
@Jiaqi-Lv Jiaqi-Lv requested a review from Copilot March 28, 2025 13:43
Copy link

@Copilot Copilot AI left a comment

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 improves type checking with mypy for the tiatoolbox models by updating type annotations, refining function signatures, and enhancing reflection-based model instantiation. Key changes include:

  • Updating type hints and return types for model functions in models_abc.py.
  • Standardizing type annotations and casts in architecture/utils.py.
  • Refining reflection logic in architecture/init.py for retrieving model and engine classes.

Reviewed Changes

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

Show a summary per file
File Description
tiatoolbox/models/models_abc.py Adjusted device handling and forward function signature with refined types
tiatoolbox/models/architecture/utils.py Updated type hints on tensor and numpy inputs, and added constant definition in UpSample2x
tiatoolbox/models/architecture/init.py Refactored path handling for pretrained weights and improved reflection for model/engine class resolution
tests/test_utils.py Expanded tests for fetch_pretrained_weights handling of string paths
.github/workflows/mypy-type-check.yml Extended files checked by mypy
Files not reviewed (1)
  • requirements/requirements.txt: Language not supported
Comments suppressed due to low confidence (3)

tiatoolbox/models/models_abc.py:58

  • [nitpick] Consider renaming the local variable 'torch_device' to 'target_device' to avoid confusion with the previously imported alias and improve readability.
torch_device = torch.device(device)

tiatoolbox/models/architecture/init.py:139

  • Add a check to verify that 'arch_module' is not None before calling getattr; this will help catch cases where the module cannot be located and lead to a clearer error.
arch_module = locate(f"tiatoolbox.models.architecture.{model_module_name}")

tiatoolbox/models/architecture/init.py:167

  • Similarly, ensure that 'engine_module' is validated for a non-None value before using getattr to avoid runtime errors if the module lookup fails.
engine_module = locate(f"tiatoolbox.models.engine.{io_module_name}")

@Jiaqi-Lv Jiaqi-Lv requested a review from shaneahmed March 28, 2025 13:44
Copy link
Member

@shaneahmed shaneahmed left a comment

Choose a reason for hiding this comment

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

Thanks @Jiaqi-Lv

@shaneahmed shaneahmed merged commit a9e34c3 into develop Apr 3, 2025
15 checks passed
@shaneahmed shaneahmed deleted the mypy-tiatoolbox-models branch April 3, 2025 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev tools Changes/Updates in Development tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants