From 5c320990f7c3664370636deeb0e31b9c5cd04e50 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 11 Dec 2025 03:40:19 -0500 Subject: [PATCH] [ty] Avoid inferring types for invalid binary expressions in string annotations (#21911) ## Summary Closes https://github.com/astral-sh/ty/issues/1847. --------- Co-authored-by: David Peter --- .../ty_python_semantic/resources/mdtest/annotations/string.md | 3 +++ .../src/types/infer/builder/type_expression.rs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/string.md b/crates/ty_python_semantic/resources/mdtest/annotations/string.md index 5777070441..db152ae907 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/string.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/string.md @@ -156,6 +156,9 @@ a: "1 or 2" b: "(x := 1)" # error: [invalid-type-form] c: "1 + 2" +# Regression test for https://github.com/astral-sh/ty/issues/1847 +# error: [invalid-type-form] +c2: "a*(i for i in [])" d: "lambda x: x" e: "x if True else y" f: "{'a': 1, 'b': 2}" diff --git a/crates/ty_python_semantic/src/types/infer/builder/type_expression.rs b/crates/ty_python_semantic/src/types/infer/builder/type_expression.rs index fbae2c8948..a3ffabe826 100644 --- a/crates/ty_python_semantic/src/types/infer/builder/type_expression.rs +++ b/crates/ty_python_semantic/src/types/infer/builder/type_expression.rs @@ -155,7 +155,6 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } // anything else is an invalid annotation: op => { - self.infer_binary_expression(binary, TypeContext::default()); self.report_invalid_type_expression( expression, format_args!(