fix TypeVar does not support unary OP despite being upper bounded by type supporting unary OP #1972#1978
fix TypeVar does not support unary OP despite being upper bounded by type supporting unary OP #1972#1978asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #1972 where TypeVars bounded by types supporting unary operators (__neg__, __pos__, __invert__) were incorrectly failing type checking.
Key Changes:
- Extended unary operator type inference to handle
Type::Quantified(bounded type parameters) - Added comprehensive test coverage for unary operators with bounded type parameters
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pyrefly/lib/alt/operators.rs | Added Type::Quantified(_) to the pattern match in unop_infer to enable method resolution via bounds |
| pyrefly/lib/test/operators.rs | Added regression test covering -foo, +foo, and ~foo operations on a PEP-695 bounded type parameter |
The implementation is correct and leverages the existing attribute lookup infrastructure that already properly handles Type::Quantified by resolving methods through the bound type. No issues were found during the review.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
stroxler
left a comment
There was a problem hiding this comment.
LGTM, I'll aim to get a second review and get it merged
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #1972
Updated unary-op inference so bounded type parameters (Type::Quantified) resolve
__neg__/__pos__/__invert__via the bound, and added a regression test for a PEP‑695 type parameter bounded by a class returning Self.Test Plan
added
test_unary_dunders_typevar_boundcovering-foo,+foo,~foofordef test[F: Foo](foo: F)