Skip to content

Preserve omitted slice positions and validate builtin sequence slices#3942

Open
ak4-sh wants to merge 1 commit into
facebook:mainfrom
ak4-sh:fix-zero-step-in-slice
Open

Preserve omitted slice positions and validate builtin sequence slices#3942
ak4-sh wants to merge 1 commit into
facebook:mainfrom
ak4-sh:fix-zero-step-in-slice

Conversation

@ak4-sh

@ak4-sh ak4-sh commented Jun 25, 2026

Copy link
Copy Markdown

Validate slice values for builtin sequences

Add tests to check for correct slice behaviour

Remove bug status from testcase since behaviour is fixed

Summary

Validate slice components for builtin list and tuple subscripts. Pyrefly now reports errors for non-index slice values like decimal steps, and for literal zero steps. Also preserve omitted slice positions when inferring slice[...] types so start, stop, and step do not shift into the wrong generic slots.

Remove the bug marker from the existing zero-step slice test since the behaviour is now fixed, and add list/tuple coverage for decimal and zero step slices.

Fixes #3768, #3896

Test Plan

  • cargo test test_slice_decimal_step
  • cargo test test_slice_zero_step

Validate slice values for builtin sequences

Add tests to check for correct slice behaviour

Remove bug status from testcase since behaviour is fixed
@meta-cla meta-cla Bot added the cla signed label Jun 25, 2026
@ak4-sh ak4-sh marked this pull request as ready for review June 25, 2026 06:29
@ak4-sh ak4-sh changed the title Preserve ommitted slice positions in slice types Preserve ommitted slice positions in slice types and fix slice behaviour Jun 25, 2026
@ak4-sh ak4-sh changed the title Preserve ommitted slice positions in slice types and fix slice behaviour Preserve omitted slice positions and validate builtin sequence slices Jun 25, 2026
@github-actions

Copy link
Copy Markdown

Diff from mypy_primer, showing the effect of this PR on open source code:

spark (https://github.com/apache/spark)
- ERROR python/pyspark/pandas/tests/test_typedef.py:190:37-53: Expected a type form, got instance of `slice[Literal['a'], type[float64], Literal['a'] | type[float64]]` [not-a-type]
+ ERROR python/pyspark/pandas/tests/test_typedef.py:190:37-53: Expected a type form, got instance of `slice[Literal['a'], type[float64], None]` [not-a-type]
- ERROR python/pyspark/pandas/tests/test_typedef.py:190:55-62: Expected a type form, got instance of `slice[Literal['b'], type[str], Literal['b'] | type[str]]` [not-a-type]
+ ERROR python/pyspark/pandas/tests/test_typedef.py:190:55-62: Expected a type form, got instance of `slice[Literal['b'], type[str], None]` [not-a-type]
- ERROR python/pyspark/pandas/tests/test_typedef.py:208:37-47: Expected a type form, got instance of `slice[Literal['a'], type[float], Literal['a'] | type[float]]` [not-a-type]
+ ERROR python/pyspark/pandas/tests/test_typedef.py:208:37-47: Expected a type form, got instance of `slice[Literal['a'], type[float], None]` [not-a-type]
- ERROR python/pyspark/pandas/tests/test_typedef.py:208:49-57: Expected a type form, got instance of `slice[Literal['b'], type[int], Literal['b'] | type[int]]` [not-a-type]
+ ERROR python/pyspark/pandas/tests/test_typedef.py:208:49-57: Expected a type form, got instance of `slice[Literal['b'], type[int], None]` [not-a-type]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new rule - zero step in slice

1 participant