Commit 2da0002
🔨 Improve
This pull request includes several bug fixes and improvements across utility functions, type checking, and testing in the codebase. The main focus is on improving error handling in image reading, refining type conversions, and enhancing test coverage for edge cases.
**Bug fixes and error handling improvements:**
* Improved `imread` in `utils/misc.py` to raise a `FileNotFoundError` when the image path does not exist and an `OSError` when OpenCV fails to read the image, ensuring clearer error reporting.
* Updated `cast_to_min_dtype` in `utils/misc.py` to use a tuple of (max_value, dtype) pairs for more robust and readable type selection.
* Fixed a bug in `dict_to_store_semantic_segmentor` by converting `layer_list` to a Python list before further processing, ensuring compatibility with downstream code. [[1]](diffhunk://#diff-dfa5a361c3c57e515728d23b53be87e0ee8da01ea04ae9cd6c39770fe3f1aaedR1480-R1487) [[2]](diffhunk://#diff-dfa5a361c3c57e515728d23b53be87e0ee8da01ea04ae9cd6c39770fe3f1aaedL1488-R1496)
* Refined coordinate type casting in `filter_coordinates` in `tools/patchextraction.py` to use `cast` for explicit type annotation.
**Testing improvements:**
* Added tests for `imread` to verify correct exceptions are raised for invalid paths and unreadable images, increasing test coverage for error scenarios.
* Added a test to ensure `compile_model` raises a `ValueError` when called with `None`, improving robustness of model compilation utilities.
**Type checking and code clarity:**
* Added a debug step to the MyPy type checking workflow and changed the import following mode to `silent` for better stability.
* Added missing imports and cleaned up imports in test files for clarity and correctness. [[1]](diffhunk://#diff-33c13e0b177bacd2f02e29bcb8aea5b49e7ce34901fd8f41fefb65defba1bd33R7) [[2]](diffhunk://#diff-33c13e0b177bacd2f02e29bcb8aea5b49e7ce34901fd8f41fefb65defba1bd33R46)
* Minor refactorings for clarity and explicitness, such as assigning the `attention` attribute in model utilities and improving variable naming in `tools/graph.py` and `utils/image.py`. [[1]](diffhunk://#diff-6eae2ccdde40d5d9c4749fb799b7777ceafbf1778f7b7f4b317af2972dde4225R328-R329) [[2]](diffhunk://#diff-a57a552474d66ef5961593e747fd21ba3fe25530b5a694dd5e8e467614bbc816L387-R391) [[3]](diffhunk://#diff-57f834801126808967286c68c43cb74bb25efaab0369210d0184e2576da66f3bL650-R655) [[4]](diffhunk://#diff-7fc02666e28590e37ff11a7ef254c9b2eb52eaf0f08017184d6e614df176ee80L6-R6)
**Model utility improvements:**
* Added an explicit check in `compile_model` to raise a `ValueError` if `model` is `None`, preventing silent failures.
These changes collectively improve code reliability, maintainability, and test coverage.
---------
Co-authored-by: Jiaqi Lv <jiaqilv@Jiaqis-MacBook-Pro.local>
Co-authored-by: Shan E Ahmed Raza <13048456+shaneahmed@users.noreply.github.com>mypy Workflow and Fix Typing Errors (#1045)1 parent 275e4e9 commit 2da0002
7 files changed
Lines changed: 78 additions & 15 deletions
File tree
- .github/workflows
- tests
- tiatoolbox
- models/architecture
- tools
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
41 | 47 | | |
42 | 48 | | |
43 | | - | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
1877 | 1879 | | |
1878 | 1880 | | |
1879 | 1881 | | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
1880 | 1888 | | |
1881 | 1889 | | |
1882 | 1890 | | |
| |||
2457 | 2465 | | |
2458 | 2466 | | |
2459 | 2467 | | |
| 2468 | + | |
| 2469 | + | |
| 2470 | + | |
| 2471 | + | |
| 2472 | + | |
| 2473 | + | |
| 2474 | + | |
| 2475 | + | |
| 2476 | + | |
| 2477 | + | |
| 2478 | + | |
| 2479 | + | |
| 2480 | + | |
| 2481 | + | |
| 2482 | + | |
| 2483 | + | |
| 2484 | + | |
| 2485 | + | |
| 2486 | + | |
| 2487 | + | |
| 2488 | + | |
| 2489 | + | |
| 2490 | + | |
| 2491 | + | |
| 2492 | + | |
| 2493 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| |||
321 | 325 | | |
322 | 326 | | |
323 | 327 | | |
| 328 | + | |
| 329 | + | |
324 | 330 | | |
325 | 331 | | |
326 | 332 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
432 | 432 | | |
433 | 433 | | |
434 | 434 | | |
435 | | - | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
436 | 439 | | |
437 | 440 | | |
438 | 441 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
647 | 647 | | |
648 | 648 | | |
649 | 649 | | |
650 | | - | |
| 650 | + | |
651 | 651 | | |
652 | 652 | | |
653 | 653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
203 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
| |||
1468 | 1475 | | |
1469 | 1476 | | |
1470 | 1477 | | |
1471 | | - | |
1472 | | - | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
1473 | 1482 | | |
1474 | 1483 | | |
1475 | | - | |
| 1484 | + | |
1476 | 1485 | | |
1477 | 1486 | | |
1478 | 1487 | | |
| |||
1939 | 1948 | | |
1940 | 1949 | | |
1941 | 1950 | | |
1942 | | - | |
1943 | | - | |
1944 | | - | |
| 1951 | + | |
| 1952 | + | |
| 1953 | + | |
| 1954 | + | |
| 1955 | + | |
| 1956 | + | |
| 1957 | + | |
| 1958 | + | |
1945 | 1959 | | |
1946 | 1960 | | |
1947 | 1961 | | |
| |||
0 commit comments