Repository navigation
Add versionadded for typing.Generator defaults - #158967
ivanovkirilg wants to merge 1 commit into
Conversation
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. |
| .. versionadded:: 3.13 | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]
>>>There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Wait: typing.Generator does exist and contains:
.. versionchanged:: 3.13
Default values for the send and return types were added.
In a project requiring Python >= 3.12, I was baffled by the following error:
especially when reading the docs for
typing.Generator, which claimed that one argument is sufficient.That is until I went to the 3.12 docs which state that one must
Hence I propose a
versionaddednote.I looked around the page for examples and determined that a plain
versionaddedtag without the note may look like it applies to the entireGenerator.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:
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.15docs.