Files
ruff/crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_assignment.md
David Peter 5ca9c15fc8 [ty] Better invalid-assignment diagnostics (#21476)
## Summary

Improve the diagnostic range for `invalid-assignment` diagnostics, and
add source annotations for the value and target type.

closes https://github.com/astral-sh/ty/issues/1556

### Before

<img width="836" height="601" alt="image"
src="https://github.com/user-attachments/assets/a48219bb-58a8-4a83-b290-d09ef50ce5f0"
/>

### After

<img width="857" height="742" alt="image"
src="https://github.com/user-attachments/assets/cfcaa4f4-94fb-459e-8d64-97050dfecb50"
/>

## Ecosystem impact

Very good! Due to the wider diagnostic range, we now pick up more `#
type: ignore` directives that were supposed to suppress an invalid
assignment diagnostic.

## Test Plan

New snapshot tests
2025-11-18 14:31:04 +01:00

670 B

Invalid assignment diagnostics

Annotated assignment

x: int = "three"  # error: [invalid-assignment]

Unannotated assignment

x: int
x = "three"  # error: [invalid-assignment]

Named expression

x: int

(x := "three")  # error: [invalid-assignment]

Multiline expressions

# fmt: off

# error: [invalid-assignment]
x: str = (
    1 + 2 + (
        3 + 4 + 5
    )
)

Multiple targets

x: int
y: str

x, y = ("a", "b")  # error: [invalid-assignment]

x, y = (0, 0)  # error: [invalid-assignment]

Shadowing of classes and functions

See shadowing.md.