Skip to content

Distinguish slice constants from runtime slice calls - #18

Closed
EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/slice-constant-normalization
Closed

EiNSTeiN- wants to merge 2 commits into
ejfkdev:mainfrom
EiNSTeiN-:fix/slice-constant-normalization

Conversation

@EiNSTeiN-

Copy link
Copy Markdown
Contributor

I am opening this PR to distinguish marshalled slice constants from runtime slice calls. The following expressions must retain their different meanings:

def select(data, stop):
    return data[:stop, :]


def runtime_call(data, stop):
    return data[slice(None, stop, None), :]

The normalizer currently converts any suitably shaped call named slice into colon syntax. For the single-axis case, data[slice(None, stop, None)] becomes:

data[:stop]

That removes the global lookup and call, so a shadowed or effectful slice callable no longer runs.

Conversely, a tuple containing actual serialized slice constants needs recursive normalization into colon syntax inside a multi-axis subscript. Currently data[:, :] can become:

data[(slice(None, None, None), slice(None, None, None))]

This introduces runtime global lookups that the constant-index source does not perform.

The replacement normalizes genuine PyObject::Slice values and tuples containing them, while preserving runtime calls. Variations include data[:stop, :], data[:, :], data[1:stop:2, :, 7], and single- or multi-axis runtime slice arguments.

Serialized slice objects are supported by marshal format 5, introduced in Python 3.14. Preserving actual runtime calls also matters for older bytecode; it does not require serialized slice constants.

@ejfkdev

ejfkdev commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Merged via consolidated PR #28 (commit e629b6c). Your fix, fixtures, behavior cases and integration test are all included and verified together: real-world corpus 6411/6411, stdlib corpus 528/528, behavior tests green on 3.9-3.14. Thanks for the detailed reports and repros!

@ejfkdev ejfkdev closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants