Skip to content

Wrong stop when calculating the slice of a range #137705

@LM-SR

Description

@LM-SR

Bug report

Bug description:

When calculating the stop value of a range, the expectation is that it will calculate the value that will match the last element following the step value. This is not the case as in the example below:

Python 3.13.5 (main, Jun 11 2025, 15:36:57) [Clang 17.0.0 (clang-1700.0.13.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> range(0, 98, 6)[6::5]
range(36, 102, 30)
>>> range(0, 98, 6)[6::5][0::]
range(36, 126, 30)

It is expected that the stop value of range(0, 98, 6)[6::5] to be 126, when it calculated to be 102. This does not affect the actual elements in the range, it is just unexpected.

CPython versions tested on:

3.13

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions