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

[red-knot] Type narrowing inside boolean expressions #13970

Merged

Conversation

TomerBin
Copy link
Contributor

Summary

This PR adds type narrowing in and and or expressions, for example:

class A: ...

x: A | None = A() if bool_instance() else None

isinstance(x, A) or reveal_type(x)  # revealed: None

Test Plan

New mdtests 😍

@TomerBin TomerBin changed the title [red-knot] Narrowing - Boolean expressions [red-knot] Type narrowing inside boolean expressions Oct 28, 2024
@TomerBin TomerBin marked this pull request as ready for review October 28, 2024 21:36
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@AlexWaygood AlexWaygood added the red-knot Multi-file analysis & type inference label Oct 28, 2024
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

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

So nice!

@carljm carljm merged commit 9a0dade into astral-sh:main Oct 29, 2024
20 checks passed
@TomerBin TomerBin deleted the tomer/boolean-operations-type-narrowing branch October 29, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants