Skip to content

gh-158077: Remove deprecated PySlice_GetIndicesEx() function - #158089

Open
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:remove_slice_get
Open

vstinner wants to merge 1 commit into
python:mainfrom
vstinner:remove_slice_get

Conversation

@vstinner

@vstinner vstinner commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Only remove the function implementation. PySlice_GetIndicesEx() remains available as a static inline function, so the API does not change.

Convert PySlice_GetIndicesEx() macro to a static inline functions. Arguments are now only evaluated once.

The function is no longer supported on limited C API older than 3.6.1.

Only remove the function implementation. PySlice_GetIndicesEx()
remains available as a static inline function, so the API does not
change.

Convert PySlice_GetIndicesEx() macro to a static inline functions.
Arguments are now only evaluated once.

The function is no longer supported on limited C API older than
3.6.1.
Comment thread Include/sliceobject.h
Py_ssize_t *step,
Py_ssize_t *slicelength);

#if !defined(Py_LIMITED_API) || (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000) || Py_LIMITED_API+0 >= 0x03060100

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that Python 3.16 should both with limited C API 3.5.x. Use Python 3.16 to target the recent stable ABI. Or use an old Python version to target an old stable ABI version. I prefer to remove (Py_LIMITED_API+0 >= 0x03050400 && Py_LIMITED_API+0 < 0x03060000).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Python 3.6 is no longer supported upstream, we may even simplify the check as Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 7).

Comment thread Include/sliceobject.h
*slicelen = PySlice_AdjustIndices(length, start, stop, *step);
return 0;
}
#define PySlice_GetIndicesEx _PySlice_GetIndicesEx

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static inline function should have a different name, so sliceobject.c can implement a function under "PySlice_GetIndicesEx" name.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. The point of the macro is that length is evaluated after calling PySlice_Unpack. This can only be implemented as a macro.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah? It wasn't obvious to me at all when I read the macro. Also, it seems like PySlice_GetIndicesEx() is not tested.

Comment thread Doc/whatsnew/3.16.rst

* Remove :c:func:`PySlice_GetIndicesEx` function, deprecated since Python 3.7.
Only remove the function implementation: :c:func:`PySlice_GetIndicesEx`
remains available as a static inline function, so the API does not change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the C API is not affected, I'm not sure that it's worth it to mention this change to users. They should not be affected in practice. (The Changelog can also be removed.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will add a test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, if you want to write tests, please go ahead! I was planning to do that after you told me that length should be evaluated later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #158120.

@read-the-docs-community

Copy link
Copy Markdown

@gvanrossum

Copy link
Copy Markdown
Member

What's the point of this PR? Nothing changes, we still have the same amount of code, it's just laid out differently. That's a lot of maintenance for a deprecated function. Why not leave things alone?

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.

3 participants