Skip to content

Consistent usage of annotation syntax #5835

@f-schnabel

Description

@f-schnabel

Is your feature request related to a problem? Please describe.
There are already some files using the new syntax for annotations.
https://github.com/Project-MONAI/MONAI/search?q=from+__future__+import+annotations
The old type aliases from the typing module are deprecated starting with python 3.9,
so to be future-prove it makes sense to migrate to the new style.

Describe the solution you'd like
Use from __future__ import annotations in all source files using annotations, so we have consistent usage (and not only in ~5 files).
The new annotations are also more readable e.g. Optional[Union[List[str], str]] vs. list[str] | str | None.

Secondly, this issue includes changing from typing import Callable, Sequence, ... to from collections.abc import Callable, Sequence, ... since the ones in the typing module are deprecated. They are interchangable even for isinstance checks (see also this stackoverflow thread).

Additional context

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