-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-128335: Make slice generic at runtime #128336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Gobot1234
commented
Dec 29, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Make slice generic #128335
@@ -560,6 +560,7 @@ static PyMethodDef slice_methods[] = { | |||
METH_O, slice_indices_doc}, | |||
{"__reduce__", (PyCFunction)slice_reduce, | |||
METH_NOARGS, reduce_doc}, | |||
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed it is maybe a little silly to be putting PEPs in these things when they aren't active docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PRs to the PEPs repo improving things like this are welcome!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if @AlexWaygood / @JelleZijlstra have opinions on this. This is done in other places. I seem to have time travelled here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
Misc/NEWS.d/next/Core_and_Builtins/2024-12-29-21-33-08.gh-issue-128334.3c5Nou.rst
Outdated
Show resolved
Hide resolved
…e-128334.3c5Nou.rst Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
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 |