Skip to content
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

Don't consider 'object' always truthy #14510

Merged
merged 1 commit into from
Jan 23, 2023
Merged

Don't consider 'object' always truthy #14510

merged 1 commit into from
Jan 23, 2023

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented 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.

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 JukkaL requested a review from ilevkivskyi January 23, 2023 13:49
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds reasonable.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JukkaL JukkaL merged commit db440ab into master Jan 23, 2023
@JukkaL JukkaL deleted the object-truthy branch January 23, 2023 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression for truthy bool with getattr
2 participants