@final class without __bool__ cannot have falsey instances by ikonst · Pull Request #16566 · python/mypy

Skip to content

Navigation Menu

Sign in

Appearance settings

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

Conversation

@ikonst

Copy link Copy Markdown

Contributor

@ikonst ikonst commented

Nov 26, 2023

edited

Loading

Once class C is final, we know that a derived class won't add a __bool__ or a __len__ so if they're missing, we can assume every instance of C to be truthy.

Relates to #16565.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

@github-actions

Copy link Copy Markdown

Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link Copy Markdown

Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Nice!

@hauntsaninja hauntsaninja merged commit 7c33e7c into python:master

Dec 4, 2023

@ikonst ikonst deleted the final-never-false branch

December 4, 2023 20:10

@KotlinIsland

Copy link Copy Markdown

Contributor

KotlinIsland commented

Jan 4, 2024

edited

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hauntsaninja hauntsaninja hauntsaninja approved these changes

+1 more reviewer

@AlexWaygood AlexWaygood AlexWaygood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@ikonst @KotlinIsland @hauntsaninja @AlexWaygood