Skip to content

MyPy issue #8149

Open
Open

Description

@KumoLiu
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)

Activity

  1. KumoLiu commented on Oct 14, 2024

    @KumoLiu
    ContributorAuthor

    related to the new release from mypy: https://pypi.org/project/mypy/#history

  2. added a commit that references this issue on Oct 15, 2024
  3. KumoLiu commented on Oct 18, 2024

    @KumoLiu
    ContributorAuthor
    mypy 1.11.2 (compiled: yes)
    monai/networks/utils.py:700:15: error: Argument "f" to "export" has incompatible type "BytesIO"; expected "Union[str, PathLike[Any], None]"  [arg-type]
    
  4. KumoLiu commented on Oct 18, 2024

    @KumoLiu
    ContributorAuthor
    mypy 1.11.2 (compiled: yes)
    monai/networks/utils.py:700:15: error: Argument "f" to "export" has incompatible type "BytesIO"; expected "Union[str, PathLike[Any], None]"  [arg-type]
    

    Hi @borisfom and @binliunls, It seems that since version 2.5.0, the f parameter in torch.onnx.export no longer accepts BytesIO. Do you have any suggestions on how we can address this mypy issue?
    https://github.com/pytorch/pytorch/blob/v2.5.0/torch/onnx/utils.py#L178
    https://github.com/Project-MONAI/MONAI/blob/dev/monai/networks/utils.py#L693

    Ignore it as a workaround in this pr: #8161 to ensure the ci pass.
    We can fix it later.

  5. borisfom commented on Oct 23, 2024

    @borisfom
    Contributor

    Ignore it as a workaround in this pr: #8161 to ensure the ci pass. We can fix it later.

    Sure, if it still works for you. Note filename=None is not uses in trt_compile. You may want to fix it anyway (by adding a temp file on the caller side) even if it's still working with new API, as this, for example, is not going to work with models > 2G:
    onnx_model = onnx.load_model_from_string(f.getvalue())

  6. added a commit that references this issue on Oct 24, 2024
    ef6d1c8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions