You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If untyped defs are disallowed, mypy requires that def __init__(self): has an explicit -> None return type, even though normally the return type is optional for __init__. This can be surprising, so it would be better for mypy to produce a special note in this case about why the return type is required even for __init__.
Another idea would be to drop the error message if using --check-untyped-defs, since the explicit return type arguably doesn't add much value.
What's more strange is that mypy doesn't complain if there are arguments passed to __init__. At least this inconsistency shouldn't happen. Either you require the return type hint to __init__ in all situation, or none at all (preferred), but not the current form.
Bit of necromancy on this thread but since it is still open, I agree with previous posters as well, it is not intuitive as it is now with two different behaviors. It leads me as a dev to first expect that there was some other strange bug either with my own project or with mypy.
Since the behavior of requiring return type when no arguments are given has been put in on purpose I think adding a custom error message would be the best solution to this confusion.
If untyped defs are disallowed, mypy requires that
def __init__(self):
has an explicit-> None
return type, even though normally the return type is optional for__init__
. This can be surprising, so it would be better for mypy to produce a special note in this case about why the return type is required even for__init__
.Another idea would be to drop the error message if using
--check-untyped-defs
, since the explicit return type arguably doesn't add much value.See #5943 for context.
The text was updated successfully, but these errors were encountered: