Skip to content

Commit 1a2e2de

Browse files
committed
Address review feedback
- Use a temp variable for the swap normalization. Tuple-unpack form (lhs, rhs = rhs, lhs) interacted badly with mypy's narrowing in mypyc-compiled mypy, producing a runtime IndexExpr-vs-StrExpr cast failure (mypy#21586). Workaround per @p-sawicki on PR #21579. - Drop test_any_dispatch_uses_generic_path. The 'Any' dispatch still calls the mypyc-compiled eq_comma, which has the specialization, so this test was not exercising the unspecialized path as claimed. The IR golden pins the specialized lowering, and eq_two_chars / eq_empty cover the fall-through behavior.
1 parent 60abe82 commit 1a2e2de

2 files changed

Lines changed: 2 additions & 11 deletions

File tree

mypyc/irbuild/expression.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,8 @@ def try_specialize_str_index_compare(
992992
"""
993993
# Normalize so the IndexExpr is on the left.
994994
if isinstance(rhs, IndexExpr) and not isinstance(lhs, IndexExpr):
995-
lhs, rhs = rhs, lhs
995+
tmp = lhs
996+
lhs, rhs = rhs, tmp
996997
# Shape: s[i] {==, !=} "x" where "x" is exactly one codepoint.
997998
if (
998999
not isinstance(lhs, IndexExpr)

mypyc/test-data/run-strings.test

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,6 @@ def test_isdigit_strings() -> None:
14141414
assert not "\U0001d7ce!".isdigit()
14151415

14161416
[case testStrIndexEqLiteralSpecialize]
1417-
from typing import Any
1418-
14191417
from testutil import assertRaises
14201418

14211419
# The specializer fires on the AST shape `IndexExpr == StrLiteral` (or the
@@ -1475,11 +1473,3 @@ def test_out_of_range_raises_indexerror() -> None:
14751473
eq_comma(s, 3)
14761474
with assertRaises(IndexError):
14771475
eq_comma(s, -4)
1478-
1479-
def test_any_dispatch_uses_generic_path() -> None:
1480-
# Going through `Any` routes through the interpreted wrapper, which
1481-
# uses the unspecialized lowering. Confirms the str surface still
1482-
# works for callers that bypass the specializer.
1483-
f: Any = eq_comma
1484-
assert f("hello,world", 5) is True
1485-
assert f("hello", 0) is False

0 commit comments

Comments
 (0)