GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-128335: Make slice generic at runtime by Gobot1234 · Pull Request #128336 · python/cpython Conversation
|
| 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.
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)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…e-128334.3c5Nou.rst Co-authored-by: Jelle Zijlstra <[email protected]>
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This looks good to me but agree it needs to be documented. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
| .. 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 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Is something like slice[float, float, int] also supported? This is necessary for, e.g., pandas.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes that should work fine. The number of arguments passed in isn't usually checked at runtime.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: Jelle Zijlstra <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.