Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrefly/lib/alt/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
|| ErrorContext::UnaryOp(x.op.as_str().to_owned(), self.for_display(t.clone()));
match t {
Type::Literal(lit) if let Some(ret) = f(lit) => ret,
Type::ClassType(_) | Type::SelfType(_) => {
Type::ClassType(_) | Type::SelfType(_) | Type::Quantified(_) => {
self.call_method_or_error(t, method, x.range, &[], &[], errors, Some(&context))
}
Type::Literal(Lit::Enum(lit_enum)) => self.call_method_or_error(
Expand Down
21 changes: 21 additions & 0 deletions pyrefly/lib/test/operators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,27 @@ assert_type(~c, Literal[100])
"#,
);

testcase!(
test_unary_dunders_typevar_bound,
r#"
from typing import Self

class Foo:
def __neg__(self) -> Self:
return self
def __pos__(self) -> Self:
return self
def __invert__(self) -> Self:
return self

def test[F: Foo](foo: F) -> F:
a: F = -foo
b: F = +foo
c: F = ~foo
return c
"#,
);

testcase!(
test_unary_error,
r#"
Expand Down