mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-07 21:25:08 +00:00
Only record constraints for calls in statement expressions
This commit is contained in:
parent
ca8f75b2f4
commit
2eae76b6e1
2 changed files with 24 additions and 15 deletions
|
@ -592,9 +592,13 @@ Let's try cases where the function annotated with `NoReturn` is some sub-express
|
||||||
from typing import NoReturn
|
from typing import NoReturn
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# TODO: this is currently not yet supported
|
||||||
|
# error: [invalid-return-type]
|
||||||
def _() -> NoReturn:
|
def _() -> NoReturn:
|
||||||
3 + sys.exit(1)
|
3 + sys.exit(1)
|
||||||
|
|
||||||
|
# TODO: this is currently not yet supported
|
||||||
|
# error: [invalid-return-type]
|
||||||
def _() -> NoReturn:
|
def _() -> NoReturn:
|
||||||
3 if sys.exit(1) else 4
|
3 if sys.exit(1) else 4
|
||||||
```
|
```
|
||||||
|
|
|
@ -1901,11 +1901,28 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
|
||||||
value,
|
value,
|
||||||
range: _,
|
range: _,
|
||||||
node_index: _,
|
node_index: _,
|
||||||
}) if self.in_module_scope() => {
|
}) => {
|
||||||
if let Some(expr) = dunder_all_extend_argument(value) {
|
if self.in_module_scope() {
|
||||||
self.add_standalone_expression(expr);
|
if let Some(expr) = dunder_all_extend_argument(value) {
|
||||||
|
self.add_standalone_expression(expr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.visit_expr(value);
|
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);
|
walk_stmt(self, stmt);
|
||||||
|
@ -2225,18 +2242,6 @@ impl<'ast> Visitor<'ast> for SemanticIndexBuilder<'_, 'ast> {
|
||||||
}
|
}
|
||||||
walk_expr(self, expr);
|
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);
|
walk_expr(self, expr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue