-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Regression for truthy bool with getattr #14480
Labels
bug
mypy got something wrong
Comments
ilinum
changed the title
Regression for truthy bool with getattr.
Regression for truthy bool with getattr
Jan 20, 2023
Using @hauntsaninja's mypy_primer, it pointed to #14178.
This is likely the same underlying issue as #14481. |
Here's a bit simpler example that reproduces the issue: def f(t: type[object]) -> None:
o: object = getattr(t, "x", "") or "" This looks different from #14481, as there are no TypedDicts involved here. |
JukkaL
added a commit
that referenced
this issue
Jan 23, 2023
There are two reasons I'm proposing this change. First, we know that many subclasses of 'object' can be falsy. Second, mypy sometimes simplifies `object | Any` into just `object`. The latter was considered always truthy, while the prior one wasn't. Now both of them are treated consistently. An alternative fix would be to not simplify unions like `object | Any`, but this seems a bit ad hoc. Fixes #14480. This doesn't just fix the regression but fixes a more general issue.
JukkaL
added a commit
that referenced
this issue
Jan 23, 2023
There are two reasons I'm proposing this change. First, we know that many subclasses of 'object' can be falsy. Second, mypy sometimes simplifies `object | Any` into just `object`. The latter was considered always truthy, while the prior one wasn't. Now both of them are treated consistently. An alternative fix would be to not simplify unions like `object | Any`, but this seems a bit ad hoc. This only has an effect when the `truthy-bool` error code is explicitly enabled. Fixes #14480. This doesn't just fix the regression but fixes a more general issue.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The following code generates an error on latest master but no on latest release (with
--enable-error-codes=truthy-bool
):It's clearly a false positive, if your run the code you see that it prints
unknown
.The text was updated successfully, but these errors were encountered: