Skip to content

Add versionadded for typing.Generator defaults - #158967

Open
ivanovkirilg wants to merge 1 commit into
python:mainfrom
ivanovkirilg:versionadded-generator-defaults
Open

ivanovkirilg wants to merge 1 commit into
python:mainfrom
ivanovkirilg:versionadded-generator-defaults

Conversation

@ivanovkirilg

Copy link
Copy Markdown

In a project requiring Python >= 3.12, I was baffled by the following error:

TypeError: Too few arguments for typing.Generator; actual 1, expected 3

especially when reading the docs for typing.Generator, which claimed that one argument is sufficient.

The SendType and ReturnType parameters default to None:
...

That is until I went to the 3.12 docs which state that one must

set the SendType and ReturnType to None:
...


Hence I propose a versionadded note.
I looked around the page for examples and determined that a plain versionadded tag without the note may look like it applies to the entire Generator.

However, the way I've worded it seems a bit verbose; feedback is welcome.

Result

I built the docs locally, this is what the note looks like in context:

image


I'm not sure if this change leans towards 'typo' or requiring an issue, so I went down the "path of least resistance" 🙂

If this is accepted, I intend to backport it to the 3.13–3.15 docs.

@python-cla-bot

python-cla-bot Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app bedevere-app Bot added awaiting review docs Documentation in the Doc dir skip news labels Oct 7, 2026
@picnixz

picnixz commented Oct 7, 2026

Copy link
Copy Markdown
Member

If this is accepted, I intend to backport it to the 3.13–3.15 docs.

It's unfortunate but 3.13 is sec-only so it doesn't accept such PRs. But we can backport it to 3.14-3.15.

Comment thread Doc/library/typing.rst
Comment on lines +476 to +477
.. versionadded:: 3.13

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.

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants