mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-29 19:17:20 +00:00
[red-knot] Type narrowing for assertions (take 2) (#17345)
## Summary Fixes #17147. This was landed in #17149 and then reverted in #17335 because it caused cycle panics in checking pybind11. #17456 fixed the cause of that panic. ## Test Plan Add new narrow/assert.md test file Co-authored-by: Matthew Mckee <matthewmckee04@yahoo.co.uk>
This commit is contained in:
parent
1918c61623
commit
e4e405d2a1
3 changed files with 65 additions and 2 deletions
|
|
@ -569,7 +569,6 @@ impl<'db> SemanticIndexBuilder<'db> {
|
|||
}
|
||||
|
||||
/// Records a visibility constraint by applying it to all live bindings and declarations.
|
||||
#[must_use = "A visibility constraint must always be negated after it is added"]
|
||||
fn record_visibility_constraint(
|
||||
&mut self,
|
||||
predicate: Predicate<'db>,
|
||||
|
|
@ -1323,6 +1322,17 @@ where
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
ast::Stmt::Assert(node) => {
|
||||
self.visit_expr(&node.test);
|
||||
let predicate = self.record_expression_narrowing_constraint(&node.test);
|
||||
self.record_visibility_constraint(predicate);
|
||||
|
||||
if let Some(msg) = &node.msg {
|
||||
self.visit_expr(msg);
|
||||
}
|
||||
}
|
||||
|
||||
ast::Stmt::Assign(node) => {
|
||||
debug_assert_eq!(&self.current_assignments, &[]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue