FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-128335: Make slice generic at runtime by Gobot1234 · Pull Request #128336 · python/cpython · GitHub

Repository navigation

gh-128335: Make slice generic at runtime - #128336

Merged
JelleZijlstra merged 13 commits into
python:mainfrom
Gobot1234:patch-4
Jan 11, 2026
Merged

JelleZijlstra merged 13 commits into
python:mainfrom
Gobot1234:patch-4

Conversation

Gobot1234 commented Dec 29, 2024 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

Gobot1234 marked this pull request as draft December 29, 2024 21:31
Gobot1234 marked this pull request as ready for review December 29, 2024 21:38
Comment thread Objects/sliceobject.c
METH_O, slice_indices_doc},
{"__reduce__", (PyCFunction)slice_reduce,
METH_NOARGS, reduce_doc},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This docstring seems misleading, as PEP 585 doesn't mention the slice class.

(Maybe PEP 585 could refer to https://typing.readthedocs.io/en/latest/guides/modernizing.html#generics-in-the-typing-module? Right now it links to documentation for __class_getitem__ that on its own isn't a replacement for PEP 585 from a reader's perspective)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Agreed it is maybe a little silly to be putting PEPs in these things when they aren't active docs.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

PRs to the PEPs repo improving things like this are welcome!

Gobot1234 Dec 29, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Curious if @AlexWaygood / @JelleZijlstra have opinions on this. This is done in other places. I seem to have time travelled here

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I do agree that our docstrings probably also shouldn't be referencing PEPs, which are, as you both note, historical documents recording decisions that were made at one point in time rather than living documentation. But all the other __class_getitem__ docstrings say this currently, so I think it makes sense to follow suit here and change all the __class_getitem__ docstrings to something better all at once as a followup

Copy link
Copy Markdown
Contributor

I think this calls for a whatsnew entry. Something like

* The :class:`slice` type now supports subscription,
  making it a :term:`generic type`.
  (Contributed by James Hilton-Balfe in :gh:`128335`.)

We should probably also add a versionchanged to the docs noting that slice is now a generic type.

Copy link
Copy Markdown
Member

This looks good to me but agree it needs to be documented.

Comment thread Doc/reference/datamodel.rst Outdated
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
JelleZijlstra merged commit 265381b into python:main Jan 11, 2026
46 checks passed
reidenong pushed a commit to reidenong/cpython that referenced this pull request Jan 12, 2026
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
.. versionadded:: 3.15

The :func:`slice` type now supports :ref:`subscription <subscriptions>`. For
example, ``slice[float]`` may be used in type annotations to indicate a slice

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is something like slice[float, float, int] also supported? This is necessary for, e.g., pandas.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes that should work fine. The number of arguments passed in isn't usually checked at runtime.

thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

7 participants


Back | FazBrowse Home | New Git URL