[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 <mail@david-peter.de>
This commit is contained in:
Charlie Marsh 2025-12-11 03:40:19 -05:00 committed by GitHub
parent 24ed28e314
commit 5c320990f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 1 deletions

View File

@ -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}"

View File

@ -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!(