-
Notifications
You must be signed in to change notification settings - Fork 88
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. 🚀 New features to boost your workflow:
|
tiatoolbox/models
mypy
Type Check tiatoolbox/models
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
…geAnalytics/tiatoolbox into mypy-tiatoolbox-models
There was a problem hiding this 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}")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jiaqi-Lv
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