JelleZijlstra / autotyping

Automatically add simple type annotations to your code
241 stars 20 forks source link

`__init__` return type should only be annotated if it has no args #47

Closed mx781 closed 1 year ago

mx781 commented 1 year ago

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?

JelleZijlstra commented 1 year ago

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.

mx781 commented 1 year ago

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

JelleZijlstra commented 1 year ago

No, I'd like to keep the current behavior of always annotating __init__. It's simpler to implement and simpler to understand.

JelleZijlstra commented 1 year ago

I'd accept a new option like --skip-redundant-init-annotation though that overrides the default and skips adding the annotation.

mx781 commented 1 year ago

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.