Skip to content

Commit 6eac240

Browse files
authored
Add regression test for recently fixed deque.copy() bug (#12648)
1 parent 9477bd8 commit 6eac240

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test-data/unit/check-selftype.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,3 +1220,21 @@ class ThingCollection(Generic[T]):
12201220
def do_thing(self) -> None:
12211221
self.index.update((idx, c) for idx, (k, c) in enumerate(self.collection))
12221222
[builtins fixtures/tuple.pyi]
1223+
1224+
[case testDequeReturningSelfFromCopy]
1225+
# Tests a bug with generic self types identified in issue #12641
1226+
from typing import Generic, Sequence, TypeVar
1227+
1228+
T = TypeVar("T")
1229+
Self = TypeVar("Self")
1230+
1231+
class deque(Sequence[T]):
1232+
def copy(self: Self) -> Self: ...
1233+
1234+
class List(Sequence[T]): ...
1235+
1236+
class Test(Generic[T]):
1237+
def test(self) -> None:
1238+
a: deque[List[T]]
1239+
# previously this failed with 'Incompatible types in assignment (expression has type "deque[List[List[T]]]", variable has type "deque[List[T]]")'
1240+
b: deque[List[T]] = a.copy()

0 commit comments

Comments
 (0)