-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
gh-141004: Document remaining iterator types #141010
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
gh-141004: Document remaining iterator types #141010
Conversation
Doc/c-api/bytearray.rst
Outdated
| .. c:var:: PyTypeObject PyByteArrayIter_Type | ||
| Type object for an iterator over a :class:`bytearray` object. Instances | ||
| of this object are returned by :meth:`!bytearray.__iter__`. |
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 would imply that all bytearray iterators have a single type, which would mean that no implementation of the C API can do the kind of optimization we did for range.
(Not too relevant for bytearray in particular, but you're adding the same docs for all the iterators.)
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.
Would you prefer that I remove the second sentence?
(I appreciate your feedback on these, by the way!)
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'd rather find some dusty corner of the docs to stash all of these away in, with something like:
.. c:var:: PyTypeObject PyByteArrayIter_Type
PyTypeObject PyBytesIter_Type
PyTypeObject PyListIter_Type
...
Type objects for iterators of various built-in objects.
Do not use these directly; prefer calling `PyObject_GetIter` instead.
Note that there is no guarantee that a given built-in type uses a given iterator
type.
For example, in CPython, iterating over :py:class:`range` will use one of two
iterator types depending on the size of the range. Other types may start using
a similar scheme in the future, without warning.
(We might want to add API to get a reverse iterator, just to discourage calling PyReversed_Type->tp_new and such.)
I think I'm sounding grumpy & terse, aren't I. Sorry! Going to sleep now :)
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 still think it'd be better to keep these types close to their friends, but I'm open to convincing. As an alternative, would you be okay with adding a glossary term for "iterator type" or something like that, and then adding the warning there?
I think I'm sounding grumpy & terse, aren't I. Sorry! Going to sleep now :)
You're good :)
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'm open to convincing
Here's my view then.
I think these are implementation details that wouldn't be exposed today. Users are better off not using them (and not exposing their own iterator types).
Their docs should target people that found them in some code and want to understand them. They should show up in a search, and tell you how to replace the API, but they shouldn't be “advertised”.
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.
Ok, I think I can get behind that. I've updated this PR to use the approach you suggested above. If we merge this, I'll remove the iterator types from the other PRs.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
Thanks @ZeroIntensity for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…GH-141010) Add documentation for each of the following: - PyByteArrayIter_Type - PyBytesIter_Type - PyListIter_Type - PyListRevIter_Type - PySetIter_Type - PyTupleIter_Type - PyRangeIter_Type - PyLongRangeIter_Type - PyDictIterKey_Type - PyDictRevIterKey_Type - PyDictIterValue_Type - PyDictRevIterValue_Type - PyDictIterItem_Type - PyDictRevIterItem_Type --------- (cherry picked from commit 35528fc) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
GH-141046 is a backport of this pull request to the 3.14 branch. |
…GH-141010) Add documentation for each of the following: - PyByteArrayIter_Type - PyBytesIter_Type - PyListIter_Type - PyListRevIter_Type - PySetIter_Type - PyTupleIter_Type - PyRangeIter_Type - PyLongRangeIter_Type - PyDictIterKey_Type - PyDictRevIterKey_Type - PyDictIterValue_Type - PyDictRevIterValue_Type - PyDictIterItem_Type - PyDictRevIterItem_Type --------- (cherry picked from commit 35528fc) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
GH-141047 is a backport of this pull request to the 3.13 branch. |
…1010) (GH-141046) gh-141004: Document missing iterator types in the C API (GH-141010) Add documentation for each of the following: - PyByteArrayIter_Type - PyBytesIter_Type - PyListIter_Type - PyListRevIter_Type - PySetIter_Type - PyTupleIter_Type - PyRangeIter_Type - PyLongRangeIter_Type - PyDictIterKey_Type - PyDictRevIterKey_Type - PyDictIterValue_Type - PyDictRevIterValue_Type - PyDictIterItem_Type - PyDictRevIterItem_Type --------- (cherry picked from commit 35528fc) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
…1010) (GH-141047) gh-141004: Document missing iterator types in the C API (GH-141010) Add documentation for each of the following: - PyByteArrayIter_Type - PyBytesIter_Type - PyListIter_Type - PyListRevIter_Type - PySetIter_Type - PyTupleIter_Type - PyRangeIter_Type - PyLongRangeIter_Type - PyDictIterKey_Type - PyDictRevIterKey_Type - PyDictIterValue_Type - PyDictRevIterValue_Type - PyDictIterItem_Type - PyDictRevIterItem_Type --------- (cherry picked from commit 35528fc) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
|
📚 Documentation preview 📚: https://cpython-previews--141010.org.readthedocs.build/en/141010/c-api/iterator.html#other-iterator-objects