[ty] Fix descriptor lookups for most types that overlap with None#19120
[ty] Fix descriptor lookups for most types that overlap with None#19120AlexWaygood merged 2 commits intomainfrom
None#19120Conversation
|
| .with_annotated_type(descriptor), | ||
| Parameter::positional_only(Some(Name::new_static("instance"))) | ||
| .with_annotated_type(not_none), | ||
| .with_annotated_type(Type::object(db)), |
There was a problem hiding this comment.
this means that we now selected overload 2 rather than overload 1 for types such as object that are not subtypes of None, but are also not disjoint from None
crates/ty_python_semantic/resources/mdtest/descriptor_protocol.md
Outdated
Show resolved
Hide resolved
| // TODO: Consider merging this signature with the one in the previous match clause, | ||
| // since the previous one is just this signature with the `self` parameters | ||
| // removed. | ||
| let not_none = Type::none(db).negate(db); |
There was a problem hiding this comment.
I think you may want to apply the same change to the match case just above, right? It's slightly harder to write a test for, because you might need to call __get__ manually? Let me know if you need help.
There was a problem hiding this comment.
thanks, yes, you're correct that we emitted false positive diagnostics for object.__str__.__get__(object(), None)() as well as object().__str__() 😆
I added a regression test!
There was a problem hiding this comment.
object.__str__.__get__(object(), None)()
Just imagine how happy users will be that this finally works correctly.
5f26ed4 to
d69aab4
Compare
Summary
Helps with astral-sh/ty#737. The problem remains for calling methods on
Noneitself, but no longer applies toobject,AlwaysTruthy,AlwaysFalsy, or protocols that are not disjoint fromNone.Test Plan
mdtests