[ty] Ensure that a function-literal type is always equivalent to itself#18227
[ty] Ensure that a function-literal type is always equivalent to itself#18227AlexWaygood merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
The changes in this file are not actually necessary to fix the bug, just a driveby fix for something that I noticed while fixing the bug
|
| fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { | ||
| self.body_scope(db) == other.body_scope(db) | ||
| && self | ||
| .into_callable_type(db) | ||
| .is_equivalent_to(db, other.into_callable_type(db)) | ||
| self.normalized(db) == other.normalized(db) | ||
| } |
There was a problem hiding this comment.
Discussed in person — I think both is_subtype_of and is_equivalent_to should follow the pattern above, using the normalized check as a fast path, but falling back on the body scope + callable check that was there previously.
(I think a lot of this will hopefully be cleaned up as part of astral-sh/ty#462)
|
1% slowdown on the cold benchmark: https://codspeed.io/astral-sh/ruff/branches/alex%2Fproperty-test-failure. I think that's acceptable here. It might well be addressed when we do astral-sh/ty#462. |
Summary
This is a short-term fix to some of our type-equivalence logic for function-literal and bound-method types. The issue was that two
Callabletypes will not be considered equivalent if any parameter in either type is unannotated (and it is obviously very common in methods for theselfparameter to be unannotated!). Following 97058e8, equivalence of twoFunctionLiteraltypes defers to equivalence of theCallableTypesupertypes of the two function-literal types.Long-term, we should clarify this situation by splitting
FunctionLiteralinto two separate variants, as described by @dcreager in astral-sh/ty#459 (comment) and astral-sh/ty#462Closes astral-sh/ty#459
Test Plan
cargo test -p ty_python_semanticQUICKCHECK_TESTS=100000 cargo test --release -p ty_python_semantic -- --ignored types::property_tests::stable