Skip to content

Commit 7d8f5e5

Browse files
committed
Remove length restriction -- it doesn't seem helpful
Also update tests.
1 parent 7f973c9 commit 7d8f5e5

File tree

3 files changed

+75
-62
lines changed

3 files changed

+75
-62
lines changed

mypyc/irbuild/expression.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,7 @@ def try_specialize_in_expr(
755755
left: Value | None = None
756756
items: list[Value] | None = None
757757

758-
# 16 is arbitrarily chosen to limit code size
759-
if isinstance(rhs, (TupleExpr, ListExpr)) and len(rhs.items) < 16:
758+
if isinstance(rhs, (TupleExpr, ListExpr)):
760759
left = builder.accept(lhs)
761760
items = [builder.accept(item) for item in rhs.items]
762761
elif isinstance(builder.node_type(rhs), RTuple):

mypyc/test-data/run-lists.test

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -480,66 +480,6 @@ def test_in_operator_various_cases() -> None:
480480
assert not list_in_mixed(object)
481481
assert list_in_mixed(type)
482482

483-
TUP2: Final = ('x', 'y')
484-
TUP1: Final = ('x',)
485-
TUP0: Final = ()
486-
487-
def test_final_tuple_in() -> None:
488-
assert 'x' + str() in TUP2
489-
assert 'y' + str() in TUP2
490-
b: object = 'z' + str() in TUP2
491-
assert not b
492-
493-
assert 'x' + str() in TUP1
494-
b2: object = 'y' in TUP1
495-
assert not b2
496-
497-
b3: object = 'x' in TUP0
498-
assert not b3
499-
500-
def test_final_tuple_not_in() -> None:
501-
assert 'z' + str() not in TUP2
502-
b: object = 'x' + str() not in TUP2
503-
assert not b
504-
b2: object = 'y' + str() not in TUP2
505-
assert not b2
506-
507-
assert 'y' + str() not in TUP1
508-
b3: object = 'x' not in TUP1
509-
assert not b2
510-
511-
assert 'x' not in TUP0
512-
513-
log = []
514-
515-
def f_a() -> str:
516-
log.append('f_a')
517-
return 'a'
518-
519-
def f_a2() -> str:
520-
log.append('f_a2')
521-
return 'a'
522-
523-
def f_b() -> str:
524-
log.append('f_b')
525-
return 'b'
526-
527-
def f_c() -> str:
528-
log.append('f_c')
529-
return 'c'
530-
531-
def test_tuple_in_order_of_evaluation() -> None:
532-
assert f_a() in (f_b(), f_a2())
533-
assert log ==["f_a", "f_b", "f_a2"]
534-
535-
log.clear()
536-
assert f_a() not in (f_b(), f_c())
537-
assert log ==["f_a", "f_b", "f_c"]
538-
539-
log.clear()
540-
assert f_a() in (f_b(), f_a2(), f_c())
541-
assert log ==["f_a", "f_b", "f_a2", "f_c"]
542-
543483
[case testListBuiltFromGenerator]
544484
def test_from_gen() -> None:
545485
source_a = ["a", "b", "c"]

mypyc/test-data/run-tuples.test

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,80 @@ def test_final_boxed_tuple() -> None:
302302
b3: object = 'y' not in TUPLE
303303
assert not b3
304304

305+
TUP2: Final = ('x', 'y')
306+
TUP1: Final = ('x',)
307+
TUP0: Final = ()
308+
309+
def test_final_tuple_in() -> None:
310+
assert 'x' + str() in TUP2
311+
assert 'y' + str() in TUP2
312+
b: object = 'z' + str() in TUP2
313+
assert not b
314+
315+
assert 'x' + str() in TUP1
316+
b2: object = 'y' in TUP1
317+
assert not b2
318+
319+
b3: object = 'x' in TUP0
320+
assert not b3
321+
322+
def test_final_tuple_not_in() -> None:
323+
assert 'z' + str() not in TUP2
324+
b: object = 'x' + str() not in TUP2
325+
assert not b
326+
b2: object = 'y' + str() not in TUP2
327+
assert not b2
328+
329+
assert 'y' + str() not in TUP1
330+
b3: object = 'x' not in TUP1
331+
assert not b2
332+
333+
assert 'x' not in TUP0
334+
335+
log = []
336+
337+
def f_a() -> str:
338+
log.append('f_a')
339+
return 'a'
340+
341+
def f_a2() -> str:
342+
log.append('f_a2')
343+
return 'a'
344+
345+
def f_b() -> str:
346+
log.append('f_b')
347+
return 'b'
348+
349+
def f_c() -> str:
350+
log.append('f_c')
351+
return 'c'
352+
353+
def test_tuple_in_order_of_evaluation() -> None:
354+
log.clear()
355+
assert f_a() in (f_b(), f_a2())
356+
assert log ==["f_a", "f_b", "f_a2"]
357+
358+
log.clear()
359+
assert f_a() not in (f_b(), f_c())
360+
assert log ==["f_a", "f_b", "f_c"]
361+
362+
log.clear()
363+
assert f_a() in (f_b(), f_a2(), f_c())
364+
assert log ==["f_a", "f_b", "f_a2", "f_c"]
365+
366+
def f_t() -> tuple[str, ...]:
367+
log.append('f_t')
368+
return ('x', 'a')
369+
370+
def test_tuple_in_non_specialized() -> None:
371+
log.clear()
372+
assert f_a() in f_t()
373+
assert log == ["f_a", "f_t"]
374+
375+
log.clear()
376+
assert f_b() not in f_t()
377+
assert log == ["f_b", "f_t"]
378+
305379
def test_add() -> None:
306380
res = (1, 2, 3, 4)
307381
assert (1, 2) + (3, 4) == res

0 commit comments

Comments
 (0)