-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MyPy disallow untyped decorators #5823
Description
Is your feature request related to a problem? Please describe.
There are some decorators that are untyped e.g. deprecated and deprecated_arg.
See also here: https://github.com/Project-MONAI/MONAI/blob/dev/monai/utils/deprecate_utils.py
These untyped decorators break the type checking of MyPy, so any function annotated with these decorators is not type checked at all.
Describe the solution you'd like
Add a type signature to these decorators, so the decorated functions are type checked.
First Proposal:
T = TypeVar('T', type, Callable)
def deprecated(
since: Optional[str] = None,
removed: Optional[str] = None,
msg_suffix: str = "",
version_val: str = __version__,
warning_category=FutureWarning,
) -> Callable[[T], T]:
...Another idea would be to set the return type to Callable[[T], Union[T, NoReturn]] since in some circumstances the decorator throws an exception and doesn't even reach the decorated code.
Also, enable disallow_untyped_decorators = True inside setup.cfg so we can be certain that all decorators are typed.
Additional context
MyPy documentation: https://mypy.readthedocs.io/en/stable/generics.html?highlight=decorator#declaring-decorators