Skip to content

Commit 3eebd9b

Browse files
committed
Allow reverse operators in protocols
1 parent 37ee432 commit 3eebd9b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

mypy/checker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1962,6 +1962,9 @@ def check_reverse_op_method(
19621962

19631963
assert defn.info
19641964

1965+
if defn.info.is_protocol:
1966+
return
1967+
19651968
# First check for a valid signature
19661969
method_type = CallableType(
19671970
[AnyType(TypeOfAny.special_form), AnyType(TypeOfAny.special_form)],

test-data/unit/check-protocols.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,17 @@ f(C()) # E: No overload variant of "f" matches argument type "C" \
15391539
[builtins fixtures/isinstance.pyi]
15401540
[typing fixtures/typing-full.pyi]
15411541

1542+
[case testProtocolReversePowWithModulo]
1543+
from typing import overload, Protocol
1544+
1545+
class PowableProto(Protocol):
1546+
@overload
1547+
def __rpow__(self, other: "PowableProto") -> "PowableProto": ...
1548+
@overload
1549+
def __rpow__(
1550+
self, other: "PowableProto", modulo: "PowableProto"
1551+
) -> "PowableProto": ...
1552+
15421553
-- Unions of protocol types
15431554
-- ------------------------
15441555

0 commit comments

Comments
 (0)