diff --git a/crates/ty_project/resources/test/corpus/88_regression_issue_17792.py b/crates/ty_project/resources/test/corpus/88_regression_issue_17792.py new file mode 100644 index 0000000000..c9977a8397 --- /dev/null +++ b/crates/ty_project/resources/test/corpus/88_regression_issue_17792.py @@ -0,0 +1,15 @@ +# Regression test for https://github.com/astral-sh/ruff/issues/17792 + +from __future__ import annotations + + +class C: ... + + +def f(arg: C): + pass + + +x, _ = f(1) + +assert x diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 6698ffa23a..ba08e40545 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -4002,7 +4002,12 @@ impl<'db> TypeInferenceBuilder<'db> { let standalone_expression = self.index.expression(expression); let types = infer_expression_types(self.db(), standalone_expression); self.extend(types); - self.expression_type(expression) + + // Instead of calling `self.expression_type(expr)` after extending here, we get + // the result from `types` directly because we might be in cycle recovery where + // `types.cycle_fallback_type` is `Some(fallback_ty)`, which we can retrieve by + // using `expression_type` on `types`: + types.expression_type(expression.scoped_expression_id(self.db(), self.scope())) } fn infer_expression_impl(&mut self, expression: &ast::Expr) -> Type<'db> {