-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Type of 'and' expressions may be too general #2716
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
Comments
With We already have a mechanism for tracking truthiness and falseness for things like this, so I think this proposal boils down to saying that user-defined classes that don't define a |
I forgot to mention that the strict optional alternative would use The reason why I'm thinking about ignoring the possibility of a subclass defining At least |
This doesn't seem to cause trouble too frequently, and there has been no activity in a long time, so I'm closing the issue. |
Mypy complains about this code, but perhaps it shouldn't (I'm assuming no
--strict-optional
):f
may return abool
object (ifa
is notNone
) orNone
(ifa
isNone
) but it can never return anA
instance (unless a subclass ofA
defines__bool__
-- which we might not care about) so the inferred type for the return value may not be what we want.I think I saw some real-world false positives caused by this, though I didn't look very carefully.
When using
--strict-optional
, we'll probably require usingbool(...)
around the return value since the type would otherwise beOptional[bool]
, which is not compatible withbool
.(I remember having a similar earlier discussion but couldn't find an existing issue.)
The text was updated successfully, but these errors were encountered: