Skip to content

Commit d7e411e

Browse files
committed
Code review
1 parent ec6f7c6 commit d7e411e

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

mypyc/test-data/irbuild-tuple.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,32 @@ L4:
389389
from typing import Tuple
390390
def f(a: Tuple[int, ...], b: Tuple[int, ...]) -> None:
391391
c = a + b
392+
d = a + (1, 2)
393+
def g(a: Tuple[int, int], b: Tuple[int, int]) -> None:
394+
c = a + b
392395
[out]
393396
def f(a, b):
394397
a, b, r0, c :: tuple
398+
r1 :: tuple[int, int]
399+
r2 :: object
400+
r3, d :: tuple
395401
L0:
396402
r0 = PySequence_Concat(a, b)
397403
c = r0
404+
r1 = (2, 4)
405+
r2 = box(tuple[int, int], r1)
406+
r3 = PySequence_Concat(a, r2)
407+
d = r3
408+
return 1
409+
def g(a, b):
410+
a, b :: tuple[int, int]
411+
r0, r1 :: object
412+
r2 :: tuple
413+
r3, c :: tuple[int, int, int, int]
414+
L0:
415+
r0 = box(tuple[int, int], a)
416+
r1 = box(tuple[int, int], b)
417+
r2 = PySequence_Concat(r0, r1)
418+
r3 = unbox(tuple[int, int, int, int], r2)
419+
c = r3
398420
return 1

mypyc/test-data/run-lists.test

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ print(g())
267267
7
268268

269269
[case testListOps]
270-
from typing import Any
270+
from typing import Any, cast
271271
from testutil import assertRaises
272272

273273
def test_slicing() -> None:
@@ -301,7 +301,12 @@ def test_add() -> None:
301301
res = [1, 2, 3, 4]
302302
assert [1, 2] + [3, 4] == res
303303
with assertRaises(TypeError, 'can only concatenate list (not "tuple") to list'):
304-
assert [1, 2] + (3, 4) == res # type: ignore[operator]
304+
assert [1, 2] + cast(Any, (3, 4)) == res
305+
l1 = [1, 2]
306+
id_l1 = id(l1)
307+
l1 += [3, 4]
308+
assert l1 == res
309+
assert id_l1 == id(l1)
305310
assert in_place_add([3, 4]) == res
306311
assert in_place_add((3, 4)) == res
307312
assert in_place_add({3, 4}) == res

mypyc/test-data/run-tuples.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ assert Record.__annotations__ == {
146146
}, Record.__annotations__
147147

148148
[case testTupleOps]
149-
from typing import Tuple, Final, List, Any, Optional
149+
from typing import Tuple, Final, List, Any, Optional, cast
150150
from testutil import assertRaises
151151

152152
def f() -> Tuple[()]:
@@ -260,4 +260,4 @@ def test_add() -> None:
260260
res = (1, 2, 3, 4)
261261
assert (1, 2) + (3, 4) == res
262262
with assertRaises(TypeError, 'can only concatenate tuple (not "list") to tuple'):
263-
assert (1, 2) + [3, 4] == res # type: ignore[operator]
263+
assert (1, 2) + cast(Any, [3, 4]) == res

0 commit comments

Comments
 (0)