Repository navigation
Commit 05160d5
authored
[ty] Diagnose invalid descriptor
## Summary
This PR reports `invalid-attribute-access` when an attribute read
implicitly calls a descriptor's `__get__` method with incompatible
arguments.
```python
class Descriptor:
def __get__(self):
pass
class C:
value = Descriptor()
C().value # error: `__get__` receives the descriptor, instance, and owner
```
Previously, descriptor lookup recovered the inferred return type from a
failed `__get__` call and discarded the call error.
The core change here is straightforward, but it ends up being a
significant diff because we need to preserve errors that we were
previously discarding during attribute lookup, and that happens deep in
the stack. Conceptually, we made this change:
```rust
// Before
member_lookup(...) -> PlaceAndQualifiers
// After
type MemberLookupResult = Result<PlaceAndQualifiers, MemberLookupError>;
member_lookup(...) -> MemberLookupResult
```
The lookup error retains the recovered member type to avoid cascading
diagnostics, and is threaded through the various lookup sites.
Closes astral-sh/ty#4129.__get__ calls (#27400)1 parent baea3d0 commit 05160d5
13 files changed
Lines changed: 1289 additions & 262 deletions
File tree
- crates/ty_python_semantic
- resources/mdtest
- regression
- src
- types
- call
- class
- infer
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
247 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
248 | 252 | | |
249 | 253 | | |
250 | 254 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
142 | 144 | | |
143 | 145 | | |
144 | 146 | | |
145 | | - | |
| 147 | + | |
146 | 148 | | |
147 | 149 | | |
148 | 150 | | |
| |||
221 | 223 | | |
222 | 224 | | |
223 | 225 | | |
224 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
225 | 229 | | |
226 | 230 | | |
227 | 231 | | |
| |||
363 | 367 | | |
364 | 368 | | |
365 | 369 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
369 | 375 | | |
370 | | - | |
| 376 | + | |
371 | 377 | | |
372 | 378 | | |
373 | 379 | | |
| |||
894 | 900 | | |
895 | 901 | | |
896 | 902 | | |
897 | | - | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
898 | 906 | | |
899 | 907 | | |
900 | 908 | | |
| |||
0 commit comments