Only record constraints for calls in statement expressions

This commit is contained in:
David Peter 2025-07-02 09:49:23 +02:00
parent ca8f75b2f4
commit 2eae76b6e1
2 changed files with 24 additions and 15 deletions

View file

@ -592,9 +592,13 @@ Let's try cases where the function annotated with `NoReturn` is some sub-express
from typing import NoReturn
import sys
# TODO: this is currently not yet supported
# error: [invalid-return-type]
def _() -> NoReturn:
3 + sys.exit(1)
# TODO: this is currently not yet supported
# error: [invalid-return-type]
def _() -> NoReturn:
3 if sys.exit(1) else 4
```

View file

@ -1901,11 +1901,28 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
value,
range: _,
node_index: _,
}) if self.in_module_scope() => {
if let Some(expr) = dunder_all_extend_argument(value) {
self.add_standalone_expression(expr);
}) => {
if self.in_module_scope() {
if let Some(expr) = dunder_all_extend_argument(value) {
self.add_standalone_expression(expr);
}
}
self.visit_expr(value);
if !self.source_type.is_stub() {
if let ast::Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() {
let expression = self.add_standalone_expression(func);
let predicate = Predicate {
node: PredicateNode::ReturnsNever(expression),
is_positive: false,
};
self.record_reachability_constraint(PredicateOrLiteral::Predicate(
predicate,
));
}
}
}
_ => {
walk_stmt(self, stmt);
@ -2225,18 +2242,6 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
}
walk_expr(self, expr);
}
ast::Expr::Call(ast::ExprCall { func, .. }) if !self.source_type.is_stub() => {
let expression = self.add_standalone_expression(func);
let predicate = Predicate {
node: PredicateNode::ReturnsNever(expression),
is_positive: false,
};
walk_expr(self, expr);
self.record_reachability_constraint(PredicateOrLiteral::Predicate(predicate));
}
_ => {
walk_expr(self, expr);
}