Skip to content

Conversation

@ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Nov 4, 2025

@bedevere-app bedevere-app bot added awaiting core review docs Documentation in the Doc dir skip news labels Nov 4, 2025
@ZeroIntensity ZeroIntensity added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes and removed docs Documentation in the Doc dir awaiting core review skip news labels Nov 4, 2025
@ZeroIntensity ZeroIntensity added docs Documentation in the Doc dir awaiting core review skip news labels Nov 4, 2025
@github-project-automation github-project-automation bot moved this to Todo in Docs PRs Nov 4, 2025
@ZeroIntensity ZeroIntensity changed the title gh-141004: Document remaining missing iterator types gh-141004: Document remaining iterator types Nov 4, 2025
Comment on lines 22 to 25
.. 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__`.
Copy link
Member

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.)

Copy link
Member Author

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!)

Copy link
Member

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 :)

Copy link
Member Author

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 :)

Copy link
Member

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”.

Copy link
Member Author

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.

ZeroIntensity and others added 2 commits November 5, 2025 07:07
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
@ZeroIntensity ZeroIntensity merged commit 35528fc into python:main Nov 5, 2025
28 checks passed
@ZeroIntensity ZeroIntensity deleted the document-missing-iterators branch November 5, 2025 14:13
@github-project-automation github-project-automation bot moved this from Todo to Done in Docs PRs Nov 5, 2025
@miss-islington-app
Copy link

Thanks @ZeroIntensity for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 5, 2025
…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>
@bedevere-app
Copy link

bedevere-app bot commented Nov 5, 2025

GH-141046 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Nov 5, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 5, 2025
…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>
@bedevere-app
Copy link

bedevere-app bot commented Nov 5, 2025

GH-141047 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Nov 5, 2025
ZeroIntensity added a commit that referenced this pull request Nov 5, 2025
…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>
ZeroIntensity added a commit that referenced this pull request Nov 5, 2025
…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>
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 MacOS M1 Refleaks NoGIL 3.13 (tier-2) has failed when building commit a3756c6.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1396/builds/1732) and take a look at the build logs.
  4. Check if the failure is related to this commit (a3756c6) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1396/builds/1732

Failed tests:

  • test.test_multiprocessing_forkserver.test_processes

Failed subtests:

  • test_repr_rlock - test.test_multiprocessing_forkserver.test_processes.WithProcessesTestLock.test_repr_rlock
  • test_sock_client_racing - test.test_asyncio.test_sock_lowlevel.SelectEventLoopTests.test_sock_client_racing

Test leaking resources:

  • test_sock_lowlevel: memory blocks

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_asyncio/test_sock_lowlevel.py", line 273, in test_sock_client_racing
    self.loop.run_until_complete(asyncio.wait_for(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
        self._basetest_sock_send_racing(listener, sock), 10))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/asyncio/base_events.py", line 725, in run_until_complete
    return future.result()
           ~~~~~~~~~~~~~^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/asyncio/tasks.py", line 507, in wait_for
    return await fut
           ^^^^^^^^^
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/test_asyncio/test_sock_lowlevel.py", line 196, in _basetest_sock_send_racing
    sock.send(b' ' * size)
    ~~~~~~~~~^^^^^^^^^^^^^
ConnectionResetError: [Errno 54] Connection reset by peer


Traceback (most recent call last):
  File "/Users/buildbot/buildarea/3.13.itamaro-macos-arm64-aws.macos-with-brew.refleak.nogil/build/Lib/test/_test_multiprocessing.py", line 1492, in test_repr_rlock
    self.assertEqual('<RLock(SomeOtherThread, nonzero)>', repr(lock))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: '<RLock(SomeOtherThread, nonzero)>' != '<RLock(None, 0)>'
- <RLock(SomeOtherThread, nonzero)>
+ <RLock(None, 0)>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants