Skip to content

Commit c8bf057

Browse files
fix
1 parent dbe3bc4 commit c8bf057

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

pyrefly/lib/alt/operators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
444444
|| ErrorContext::UnaryOp(x.op.as_str().to_owned(), self.for_display(t.clone()));
445445
match t {
446446
Type::Literal(lit) if let Some(ret) = f(lit) => ret,
447-
Type::ClassType(_) | Type::SelfType(_) => {
447+
Type::ClassType(_) | Type::SelfType(_) | Type::Quantified(_) => {
448448
self.call_method_or_error(t, method, x.range, &[], &[], errors, Some(&context))
449449
}
450450
Type::Literal(Lit::Enum(lit_enum)) => self.call_method_or_error(

pyrefly/lib/test/operators.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,27 @@ assert_type(~c, Literal[100])
286286
"#,
287287
);
288288

289+
testcase!(
290+
test_unary_dunders_typevar_bound,
291+
r#"
292+
from typing import Self
293+
294+
class Foo:
295+
def __neg__(self) -> Self:
296+
return self
297+
def __pos__(self) -> Self:
298+
return self
299+
def __invert__(self) -> Self:
300+
return self
301+
302+
def test[F: Foo](foo: F) -> F:
303+
a: F = -foo
304+
b: F = +foo
305+
c: F = ~foo
306+
return c
307+
"#,
308+
);
309+
289310
testcase!(
290311
test_unary_error,
291312
r#"

0 commit comments

Comments
 (0)