-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
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
- PEP 585
- Documentation to the typing module
- Old discussion about this topic: 4148 Enhance engine iteration logic and the typehints #4150 (comment)