Skip to content

Conversation

@asukaminato0721
Copy link
Contributor

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_bound covering -foo, +foo, ~foo for def test[F: Foo](foo: F)

Copilot AI review requested due to automatic review settings January 1, 2026 15:16
@meta-cla meta-cla bot added the cla signed label Jan 1, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions

This comment has been minimized.

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Contributor

@stroxler stroxler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I'll aim to get a second review and get it merged

@meta-codesync
Copy link

meta-codesync bot commented Jan 10, 2026

@stroxler has imported this pull request. If you are a Meta employee, you can view this in D90429109.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeVar does not support unary OP despite being upper bounded by type supporting unary OP

2 participants