Skip to content

Commit 2eae76b

Browse files
committed
Only record constraints for calls in statement expressions
1 parent ca8f75b commit 2eae76b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

crates/ty_python_semantic/resources/mdtest/terminal_statements.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,13 @@ Let's try cases where the function annotated with `NoReturn` is some sub-express
592592
from typing import NoReturn
593593
import sys
594594

595+
# TODO: this is currently not yet supported
596+
# error: [invalid-return-type]
595597
def _() -> NoReturn:
596598
3 + sys.exit(1)
597599

600+
# TODO: this is currently not yet supported
601+
# error: [invalid-return-type]
598602
def _() -> NoReturn:
599603
3 if sys.exit(1) else 4
600604
```

crates/ty_python_semantic/src/semantic_index/builder.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,11 +1901,28 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
19011901
value,
19021902
range: _,
19031903
node_index: _,
1904-
}) if self.in_module_scope() => {
1905-
if let Some(expr) = dunder_all_extend_argument(value) {
1906-
self.add_standalone_expression(expr);
1904+
}) => {
1905+
if self.in_module_scope() {
1906+
if let Some(expr) = dunder_all_extend_argument(value) {
1907+
self.add_standalone_expression(expr);
1908+
}
19071909
}
1910+
19081911
self.visit_expr(value);
1912+
1913+
if !self.source_type.is_stub() {
1914+
if let ast::Expr::Call(ast::ExprCall { func, .. }) = value.as_ref() {
1915+
let expression = self.add_standalone_expression(func);
1916+
1917+
let predicate = Predicate {
1918+
node: PredicateNode::ReturnsNever(expression),
1919+
is_positive: false,
1920+
};
1921+
self.record_reachability_constraint(PredicateOrLiteral::Predicate(
1922+
predicate,
1923+
));
1924+
}
1925+
}
19091926
}
19101927
_ => {
19111928
walk_stmt(self, stmt);
@@ -2225,18 +2242,6 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
22252242
}
22262243
walk_expr(self, expr);
22272244
}
2228-
ast::Expr::Call(ast::ExprCall { func, .. }) if !self.source_type.is_stub() => {
2229-
let expression = self.add_standalone_expression(func);
2230-
2231-
let predicate = Predicate {
2232-
node: PredicateNode::ReturnsNever(expression),
2233-
is_positive: false,
2234-
};
2235-
2236-
walk_expr(self, expr);
2237-
2238-
self.record_reachability_constraint(PredicateOrLiteral::Predicate(predicate));
2239-
}
22402245
_ => {
22412246
walk_expr(self, expr);
22422247
}

0 commit comments

Comments
 (0)