-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Consistent usage of annotation syntax #5836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistent usage of annotation syntax #5836
Conversation
|
There are some special cases, since these subscriptable types are only allowed as annotations but not inside casts. Therefore, |
|
thanks, could you please also review the pyupgrade configs |
I see! I believe it is better to ignore those typings instead of keeping a deprecated type. |
…ns`) and don't use deprecated typing aliases (instead use `collections.abc`) Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
Signed-off-by: Behrooz <3968947+drbeh@users.noreply.github.com>
for more information, see https://pre-commit.ci
24a9196 to
9f4c805
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we still need the deprecated types here, since the new ones only work inside annotations, but this is creating a type alias.
https://github.com/Shadow-Devil/MONAI/blob/9f4c8059491af22c7d89f02f8d8ed804206868e3/monai/transforms/spatial/array.py#L111
|
looks like it's feasible to ensure the Line 157 in 6060a47
could you please add this: |
Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
…isort Signed-off-by: Felix Schnabel <f.schnabel@tum.de>
for more information, see https://pre-commit.ci
This now also adds the imports to |
|
/black |
Signed-off-by: monai-bot <monai.miccai2019@gmail.com>
|
/build |
We have until 2025 to update this!😉 This behavior is accepted in 3.10 where we can define |
Fixes #5835.
Description
Use
from __future__ import annotationsin 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, ...tofrom collections.abc import Callable, Sequence, ...since the ones in thetypingmodule are deprecated. They are interchangeable even forisinstancechecks (see also this stackoverflow thread).Types of changes
./runtests.sh --quick --unittests --disttests.