[ty] relax the attribute narrowing condition#22440
Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unresolved-attribute |
187 | 20 | 0 |
unsupported-operator |
3 | 86 | 50 |
not-subscriptable |
1 | 100 | 0 |
possibly-missing-attribute |
26 | 33 | 35 |
invalid-assignment |
22 | 4 | 5 |
invalid-argument-type |
16 | 5 | 9 |
no-matching-overload |
21 | 2 | 0 |
unused-type-ignore-comment |
3 | 6 | 0 |
invalid-parameter-default |
0 | 0 | 7 |
invalid-return-type |
1 | 1 | 2 |
not-iterable |
0 | 0 | 2 |
possibly-unresolved-reference |
0 | 2 | 0 |
call-non-callable |
1 | 0 | 0 |
missing-argument |
1 | 0 | 0 |
| Total | 282 | 259 | 110 |
b6d09c3 to
8238ad4
Compare
|
The mypy_primer results look reasonable. |
carljm
left a comment
There was a problem hiding this comment.
Thank you! The logic here looks solid. Some suggested renamings (or non-renamings) and comment updates. One question I don't quite understand about why the existing exception for Unknown wasn't effective.
crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md
Outdated
Show resolved
Hide resolved
crates/ty_python_semantic/resources/mdtest/narrow/assignment.md
Outdated
Show resolved
Hide resolved
|
Have you done any analysis of the ecosystem results here? |
Co-authored-by: Carl Meyer <[email protected]>
Co-authored-by: Carl Meyer <[email protected]>
Co-Authored-By: Carl Meyer <[email protected]>
The latest results show that this PR has removed many more false positive errors. Many of the newly added errors are caused by dynamically adding attributes to objects. |
|
Looks great! BTW if your PR is reviewed with a green checkmark (approved), you should feel free to merge it yourself after addressing any comments, unless you feel there is something in the comments that needs more discussion, or the changes are large and you want re-review (then you can request re-review). |
Summary
Fixes astral-sh/ty#2134
This PR is based on the "pragmatism" that narrowing should only be disabled when an attribute is a data descriptor, and should be left as is when it might be a data descriptor.
I believe this is somewhat justified given the fact that the current behavior is not strictly safe either.
This code doesn't throw an error, and there's nothing inherently unsound about it, but the narrowing result is still incorrect.
Even if the class attribute is
Undefined, there is the possibility of dynamic attribute additions or additions in subclasses (and this issue persists even if we don't mark implicit attribute types withUnknown |).But if we take this into account, this kind of narrowing of implicit attributes becomes completely inapplicable!
I'd like to see the results of mypy_primer and decide whether this idea makes sense.
Test Plan
mdtest updated