Skip to content

Commit ba6bf0a

Browse files
fix(collections): add deque reverse multiplication
Declare `deque.__rmul__` so type checkers accept multiplication with an integer on the left. Add regression coverage for the reported false positive. Refs: #16034 Signed-off-by: Jason Scheffel <contact@jasonscheffel.com>
1 parent 35c51b4 commit ba6bf0a

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from collections import deque
2+
from typing_extensions import assert_type
3+
4+
assert_type(3 * deque([1, 2, 3]), deque[int])

stdlib/collections/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ class deque(MutableSequence[_T]):
277277
def __iadd__(self, value: Iterable[_T], /) -> Self: ...
278278
def __add__(self, value: Self, /) -> Self: ...
279279
def __mul__(self, value: int, /) -> Self: ...
280+
def __rmul__(self, value: int, /) -> Self: ...
280281
def __imul__(self, value: int, /) -> Self: ...
281282
def __lt__(self, value: deque[_T], /) -> bool: ...
282283
def __le__(self, value: deque[_T], /) -> bool: ...

0 commit comments

Comments
 (0)