[red-knot] Document current state of attribute assignment diagnostics#16746
[red-knot] Document current state of attribute assignment diagnostics#16746
Conversation
|
| 11 | instance.attr = 1 # error: [invalid-assignment] | ||
| | ^^^^^^^^^^^^^ Invalid assignment to data descriptor attribute `attr` on type `C` with custom `__set__` method |
There was a problem hiding this comment.
Not for fixing in this PR, but just noting it seems like we are currently inconsistent about whether we blame an invalid-assignment error on the target, on the RHS, or on the entire expression. I'm seeing that in case of x: int = "foo" we mark the entire expression, in x = "foo" (with a separate prior x: int) we mark just the target, and now here in these attribute cases we also mark just the target. Pyright seems to be consistent about always marking the RHS, and I can see the justification for that.
There was a problem hiding this comment.
I also thought it would be more intuitive to highlight the RHS, but didn't want to change behavior in my last PR or here. But that should be easy to fix.
* main: [red-knot] Use `try_call_dunder` for augmented assignment (#16717) [red-knot] Document current state of attribute assignment diagnostics (#16746) [red-knot] Case sensitive module resolver (#16521) [red-knot] Very minor simplification of the render tests (#16759) [syntax-errors] Unparenthesized assignment expressions in sets and indexes (#16404) ruff_db: add a new diagnostic renderer ruff_db: add `context` configuration red_knot: plumb through `DiagnosticFormat` to the CLI ruff_db: add concise diagnostic mode [syntax-errors] Star annotations before Python 3.11 (#16545) [syntax-errors] Star expression in index before Python 3.11 (#16544) Ruff 0.11.0 (#16723) [red-knot] Preliminary tests for typing.Final (#15917) [red-knot] fix: improve type inference for binary ops on tuples (#16725) [red-knot] Assignments to attributes (#16705) [`pygrep-hooks`]: Detect file-level suppressions comments without rul… (#16720) Fallback to requires-python in certain cases when target-version is not found (#16721)
Summary
A follow-up to #16705 which documents various kinds of diagnostics that can appear when assigning to an attribute.
Test Plan
New snapshot tests.