Skip to content
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

Don't require -> None on __init__ #3358

Closed
Daenyth opened this issue May 12, 2017 · 6 comments
Closed

Don't require -> None on __init__ #3358

Daenyth opened this issue May 12, 2017 · 6 comments

Comments

@Daenyth
Copy link

Daenyth commented May 12, 2017

There's no code where __init__ should return anything except None, so requiring -> None on it is just useless boilerplate.

I think it should be permitted to omit it, and that it should be inferred, as with self parameters not requiring annotation.

@ilevkivskyi
Copy link
Member

This was already considered, see this section of PEP 484:

(Note that the return type of __init__ ought to be annotated with -> None. The reason for this is subtle. If __init__ assumed a return annotation of -> None, would that mean that an argument-less, un-annotated __init__ method should still be type-checked? Rather than leaving this ambiguous or introducing an exception to the exception, we simply say that __init__ ought to have a return annotation; the default behavior is thus the same as for other methods.)

@Daenyth
Copy link
Author

Daenyth commented May 12, 2017

That's reasonable. I guess I can adjust my IDE snippet to just include it

@ijstokes
Copy link

ijstokes commented Aug 6, 2018

For others who end up here, it looks like this point is still open for debate in #604 (and perhaps this should be marked as a Duplicate that issue).

This quote from Guido is worth considering: #604 (comment)

Hm. I think it'd suck if we'd have to develop the habit of adding explicit
"-> None" to all init methods just to make mypy happy.

I'm with him on that.

@gmolau
Copy link
Contributor

gmolau commented Feb 20, 2019

Is there any way to disable this particular warning?

@gvanrossum
Copy link
Member

@gmolau

Is there any way to disable this particular warning?

What warning? You no longer need to put a return type on __init__(), unless it has no arguments other than self.

@gmolau
Copy link
Contributor

gmolau commented Feb 20, 2019

@gvanrossum Ah sorry, I was on an old mypy version. Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants