This is pretty sensible idiomatic code. Arguably there might be some other appropriate annotation to write for the return type; bracketing that question, it looks to be perfectly well-typed code that shouldn't produce an error. It's also not immediately clear to me how to work around it, except I guess with a # type: ignore.
I suspect this is related to the complicated treatment we give in some places to None as a return type -- cf #1509, #299, #359 -- and that treating None in a more regular way as discussed in #1278 and #1847 would fix it.
It may also be related to #1933, but I haven't yet read through that discussion to understand what's going on there.
Activity
ddfisher commented on Aug 4, 2016
This no longer appears to be a problem. I think this was fixed by #1980.
ambv commented on Jun 14, 2017
This is fixed for the function syntax, e.g. this doesn't return an error:
However, this still does:
Error:
gvanrossum commented on Jun 14, 2017
Can you open a new issue?
ambv commented on Jun 14, 2017
Will do.