@@ -2487,6 +2487,60 @@ reveal_type(Num3() + Num1()) # N: Revealed type is "__main__.Num3"
24872487reveal_type(Num2() + Num3()) # N: Revealed type is "__main__.Num2"
24882488reveal_type(Num3() + Num2()) # N: Revealed type is "__main__.Num3"
24892489
2490+ [case testReverseOperatorWithOverloads3]
2491+ from typing import Union, overload
2492+
2493+ class A:
2494+ def __mul__(self, value: A, /) -> A: ...
2495+ def __rmul__(self, value: A, /) -> A: ...
2496+
2497+ class B:
2498+ @overload
2499+ def __mul__(self, other: B, /) -> B: ...
2500+ @overload
2501+ def __mul__(self, other: A, /) -> str: ...
2502+ def __mul__(self, other: Union[B, A], /) -> Union[B, str]: pass
2503+
2504+ @overload
2505+ def __rmul__(self, other: B, /) -> B: ...
2506+ @overload
2507+ def __rmul__(self, other: A, /) -> str: ...
2508+ def __rmul__(self, other: Union[B, A], /) -> Union[B, str]: pass
2509+
2510+ [case testReverseOperatorWithOverloadsNested]
2511+ from typing import Union, overload
2512+
2513+ class A:
2514+ def __mul__(self, value: A, /) -> A: ...
2515+ def __rmul__(self, value: A, /) -> A: ...
2516+
2517+ class B:
2518+ @overload
2519+ def __mul__(self, other: B, /) -> B: ...
2520+ @overload
2521+ def __mul__(self, other: A, /) -> str: ...
2522+ def __mul__(self, other: Union[B, A], /) -> Union[B, str]: pass
2523+
2524+ @overload
2525+ def __rmul__(self, other: B, /) -> B: ...
2526+ @overload
2527+ def __rmul__(self, other: A, /) -> str: ...
2528+ def __rmul__(self, other: Union[B, A], /) -> Union[B, str]:
2529+ class A1:
2530+ def __add__(self, other: C1) -> int: ...
2531+
2532+ class B1:
2533+ def __add__(self, other: C1) -> int: ...
2534+
2535+ class C1:
2536+ @overload
2537+ def __radd__(self, other: A1) -> str: ... # E: Signatures of "__radd__" of "C1" and "__add__" of "A1" are unsafely overlapping
2538+ @overload
2539+ def __radd__(self, other: B1) -> str: ... # E: Signatures of "__radd__" of "C1" and "__add__" of "B1" are unsafely overlapping
2540+ def __radd__(self, other): pass
2541+
2542+ return ""
2543+
24902544[case testDivReverseOperator]
24912545# No error: __div__ has no special meaning in Python 3
24922546class A1:
0 commit comments