`__init__` return type should only be annotated if it has no args
Closed this issue · 5 comments
Mypy has not required __init__
to have a -> None
return annotation for a while (except in the cases of no-arg constructors). I was able to disable it entirely by monkeypatching SIMPLE_MAGICS
, but it feels like a more proper solution that distinguishes between no-arg and some-arg constructors would be appropriate here.
@JelleZijlstra would such a change be trivial to add?
I would prefer to keep annotating __init__
. It's potentially confusing for mypy users when their constructors suddenly aren't typechecked if they have no arguments.
It wouldn't be terribly difficult to skip adding a return annotation to __init__
only if there are typed arguments, though.
Yes, agreed the latter is the desirable behaviour - otherwise it ends up adding needless boilerplate. Does the fact that it's not terribly difficult mean we could see this land soon in autotyping, or that I'm welcome to file a PR for it? :P
No, I'd like to keep the current behavior of always annotating __init__
. It's simpler to implement and simpler to understand.
I'd accept a new option like --skip-redundant-init-annotation
though that overrides the default and skips adding the annotation.
Alright - I'll see if I can get that to work and file a PR when I do. If I don't reply back in a few days this can probably be closed as a wontfix.