Skip to content

Commit b473135

Browse files
committed
Allow ternary __rpow__ in protocols
1 parent 629f456 commit b473135

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

mypy/checker.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,6 +1696,7 @@ def check_funcdef_item(
16961696
if (
16971697
defn.info
16981698
and self.is_reverse_op_method(name)
1699+
and not defn.info.is_protocol
16991700
and defn not in self.overload_impl_stack
17001701
):
17011702
# TODO: we should use decorated signature for this check.

test-data/unit/check-protocols.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4809,3 +4809,12 @@ bad_rep(t) # E: Argument 1 to "bad_rep" has incompatible type "C"; expected "P[
48094809
# N: Got: \
48104810
# N: def rep(self) -> C
48114811
[builtins fixtures/tuple.pyi]
4812+
4813+
[case testProtocolTernaryRpow]
4814+
from typing import Protocol
4815+
4816+
class PowableProto(Protocol):
4817+
def __pow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto":
4818+
...
4819+
def __rpow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto":
4820+
...

0 commit comments

Comments
 (0)