Project-MONAI / Project-MONAI/MONAI

MyPy issue

Open
#8,149 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.7k
Forks
1.6k
Avg merge
5d 1h
Merged PRs (30d)
20

Description

mypy 1.12.0 (compiled: yes)
monai/data/utils.py:562:17: error: Item "ItemsView[Any, Any]" of "Union[Iterator[tuple[Any, Any]], ItemsView[Any, Any], enumerate[Any]]" has no attribute "__next__"  [union-attr]
monai/transforms/utils.py:1130:25: error: Incompatible types in assignment (expression has type "Union[int, float, Any]", target has type "int")  [assignment]
monai/transforms/utils.py:1131:23: error: Incompatible types in assignment (expression has type "Union[int, float, Any]", target has type "int")  [assignment]
monai/transforms/croppad/functional.py:194:17: error: Incompatible types in assignment (expression has type "Union[Any, Size]", variable has type "list[Any]")  [assignment]
monai/transforms/utility/dictionary.py:738:23: error: Item "Hashable" of "Union[Any, Collection[Hashable], Hashable]" has no attribute "__iter__" (not iterable)  [union-attr]
monai/transforms/io/array.py:503:30: error: "str" not callable  [operator]
monai/transforms/io/array.py:507:35: error: Incompatible types in assignment (expression has type "Union[Any, ImageWriter]", variable has type "None")  [assignment]
monai/metrics/utils.py:206:20: error: Incompatible return value type (got "Union[tuple[Any, Any], tuple[Any, Any, Any, Any]]", expected "tuple[NdarrayTensor, NdarrayTensor]")  [return-value]
monai/bundle/reference_resolver.py:245:21: error: Item "dict_items[Any, Any]" of "Union[Iterator[tuple[Any, Any]], dict_items[Any, Any], enumerate[Any]]" has no attribute "__next__"  [union-attr]
monai/bundle/reference_resolver.py:247:13: error: Incompatible types in "yield" (actual type "tuple[Union[Any, int], str, Any]", expected type "tuple[str, str, Any]")  [misc]
monai/apps/deepgrow/dataset.py:159:45: error: Argument 1 to "sum" has incompatible type "Optional[Any]"; expected "Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]]]"  [arg-type]
monai/apps/deepgrow/dataset.py:178:35: error: Item "None" of "Optional[Any]" has no attribute "flatten"  [union-attr]
tests/test_resample_backends.py:36:80: error: List item 4 has incompatible type "tuple[int, int, int, int]"; expected "Union[tuple[int, int, int], str, dict[str, Optional[str]], type[floating[Any]], type[floating[Any]]]"  [list-item]
tests/test_resample_backends.py:41:60: error: List item 1 has incompatible type "Union[type[int], type[float], type[floating[Any]], type[floating[Any]]]"; expected "Union[tuple[int, int, int], str, dict[str, Optional[str]], type[floating[Any]], type[floating[Any]]]"  [list-item]
tests/test_resample_backends.py:42:60: error: List item 1 has incompatible type "Union[type[int], type[float], type[floating[Any]], type[floating[Any]]]"; expected "Union[tuple[int, int, int], str, dict[str, Optional[str]], type[floating[Any]], type[floating[Any]]]"  [list-item]
tests/test_resample_backends.py:42:82: error: List item 4 has incompatible type "tuple[int, int, int, int]"; expected "Union[tuple[int, int, int], str, dict[str, Optional[str]], type[floating[Any]], type[floating[Any]]]"  [list-item]
monai/apps/pathology/transforms/post/dictionary.py:406:47: error: Argument 2 to "__call__" of "GenerateInstanceCentroid" has incompatible type "Optional[Any]"; expected "Union[Sequence[int], int]"  [arg-type]
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:241:12: error: Unsupported operand types for % ("int" and "Sequence[int]")  [operator]
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:241:12: note: Right operand is of type "Union[Any, Sequence[int], int]"
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:242:23: error: Unsupported operand types for * ("int" and "Sequence[int]")  [operator]
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:242:23: note: Both left and right operands are unions
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:242:24: error: Unsupported operand types for // ("int" and "Sequence[int]")  [operator]
monai/apps/generation/maisi/networks/autoencoderkl_maisi.py:242:24: note: Right operand is of type "Union[Any, Sequence[int], int]"
tests/test_trt_compile.py:84:13: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
Found 20 errors in 11 files (checked 1199 source files)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run mypy 1.12.0 against the 1,199 checked source files and reproduce the 20 errors listed in monai/data/utils.py, monai/transforms, monai/metrics, monai/bundle, monai/apps, and tests/test_resample_backends.py. Read the reported lines and their surrounding type annotations first; done means the listed type-checking errors are resolved without breaking the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.