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
It looks like this is because in typeshed, NotImplemented is given type Any -- if it had pretty much any other type that doesn't derive from BaseException it would be flagged.
Unfortunately if we change it to what it really is (a magic singleton) then everything that returnsNotImplemented will be flagged as an error unless we special-case that value in mypy (preferably only on binary operators). So this isn't a "please go fix it in typeshed" response -- we have to do two things in concert.
Honestly if we're going to special-case `NotImplemented` I'd prefer to
special-case `return NotImplemented`, so we can give `NotImplemented` a
better type than `Any`.
A very easy but hacky way to fix this is to annotate NotImplemented as NoReturn. The latter is a subtype of al types, so it will be accepted as a return value, but it is not Any so it will be invalid in some other situations such as raising it.
Activity
gvanrossum commentedon Oct 1, 2018
It looks like this is because in typeshed,
NotImplementedis given typeAny-- if it had pretty much any other type that doesn't derive fromBaseExceptionit would be flagged.Unfortunately if we change it to what it really is (a magic singleton) then everything that returns
NotImplementedwill be flagged as an error unless we special-case that value in mypy (preferably only on binary operators). So this isn't a "please go fix it in typeshed" response -- we have to do two things in concert.JukkaL commentedon Oct 2, 2018
One option would be to special case only
raise NotImplementedandraise NotImplemented(...)to generate an error.gvanrossum commentedon Oct 2, 2018
JukkaL commentedon Oct 2, 2018
That's a very good point. Maybe
return NotImplementedshould be only valid in relavant dunder methods (or with a sufficiently permissive return type)?gvanrossum commentedon Oct 2, 2018
Right, that's what I was trying to say earlier. :-)
ilevkivskyi commentedon Oct 2, 2018
A very easy but hacky way to fix this is to annotate
NotImplementedasNoReturn. The latter is a subtype of al types, so it will be accepted as a return value, but it is notAnyso it will be invalid in some other situations such as raising it.Emit error for "raise NotImplemented" (#17890)
JukkaL commentedon Oct 9, 2024
Fixed in #17890.