Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ The ``SendType`` and ``ReturnType`` parameters default to :const:`!None`::
yield start
start += 1

.. versionadded:: 3.13

Comment on lines +476 to +477

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.

We usually use versionadded when we add a new top-level object / function / module / method and versionchanged otherwise when we change something that already exists.

In addition, we put the version* changes at the end of the section for the object. As such, I would suggest that you change the entry of collections.abc.Generator instead of 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.

The docs update can't go on collections.abc.Generator because collections.abc.Generator has never validated the number of arguments passed as strictly as typing.Generator. It's always been allowed at runtime to pass only a single argument to collections.abc.Generator. On Python 3.12:

% uvx python3.12
Python 3.12.13 (main, May 10 2026, 19:20:41) [Clang 22.1.3 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing, collections.abc
>>> typing.Generator[int]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alexwaygood/.local/share/uv/python/cpython-3.12.13-macos-aarch64-none/lib/python3.12/typing.py", line 398, in inner
    return func(*args, **kwds)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/alexwaygood/.local/share/uv/python/cpython-3.12.13-macos-aarch64-none/lib/python3.12/typing.py", line 1482, in __getitem__
    _check_generic(self, params, self._nparams)
  File "/Users/alexwaygood/.local/share/uv/python/cpython-3.12.13-macos-aarch64-none/lib/python3.12/typing.py", line 304, in _check_generic
    raise TypeError(f"Too {'many' if alen > elen else 'few'} arguments for {cls};"
TypeError: Too few arguments for typing.Generator; actual 1, expected 3
>>> collections.abc.Generator[int]
collections.abc.Generator[int]
>>>

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.

Oh. Mmmh, but it's weird then that this is in middle of a prose paragraph where we link to collections.abc.Generator and not typing.Generator.

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.

Wait: typing.Generator does exist and contains:

   .. versionchanged:: 3.13
      Default values for the send and return types were added.

Added default :const:`!None` for ``SendType`` and ``ReturnType``

It is also possible to set these types explicitly::

def infinite_stream(start: int) -> Generator[int, None, None]:
Expand Down
Loading