Skip to content

NamedTuple now narrows to bool correctly, when __bool__ is defined #11822

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

Merged
merged 2 commits into from
Jan 9, 2022
Merged

NamedTuple now narrows to bool correctly, when __bool__ is defined #11822

merged 2 commits into from
Jan 9, 2022

Conversation

sobolevn
Copy link
Member

This is debatable, because __bool__ can be defined as return True or return False.
And we don't check this in scope of this PR.

But, it solves the given problem.

Closes #11819

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

steam.py (https://github.com/Gobot1234/steam.py)
- steam/utils.py:141: error: Incompatible types in assignment (expression has type "int", variable has type "Optional[Union[Literal[0], Literal[1], Literal[2], Literal[4]]]")  [assignment]

@JelleZijlstra JelleZijlstra merged commit c0c86d0 into python:master Jan 9, 2022
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.

Overriding __bool__ in NamedTuple doesn't work
3 participants