This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Move documentation for typed generic forms of standard collections to collections.abc
Type: enhancement Stage: needs patch
Components: Documentation Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, gvanrossum, kj, pxeger, rhettinger, stutzbach
Priority: normal Keywords:

Created on 2021-10-03 13:12 by pxeger, last changed 2022-04-11 14:59 by admin.

Messages (6)
msg403085 - (view) Author: Patrick Reader (pxeger) * Date: 2021-10-03 13:12
Currently the documentation for the generic forms (e.g. what the parameters in square brackets mean) of standard collections (e.g. collections.abc.Generator), is still on the typing page (https://docs.python.org/3.10/library/typing.html#typing.Generator).

This is from before PEP 585 was implemented, which deprecated the ones in typing in favour of the aliases in collections.abc. The documentation for these should be moved, or at least linked to, in the collections.abc page. The same applies to builtin types like list which can now also be directly parameterised.

In the case of Generator, for example, the text at https://docs.python.org/3.10/library/typing.html#typing.Generator, "A generator can be annotated...", should be moved to 
https://docs.python.org/3.10/library/collections.abc.html#collections.abc.Generator.

I chose Generator as an example, because it has three parameters YieldType, SendType, ReturnType whose order I can't remember and need to look up. For some types, such as Iterable, the meaning of the parameter is quite straightforward, so little documentation is needed (so https://docs.python.org/3.10/library/typing.html#typing.Iterable just says "A generic form of https://docs.python.org/3.10/library/collections.abc.html#collections.abc.Iterable"), but there should still be a note on the collections.abc page that it can be parameterised.

Perhaps there should also be a message saying "new in version 3.9: this can now be parameterised" on each ABC collection.

I can see that it might not be desirable to have this information scattered across other pages, because it is fundamentally about typing and pretty unrelated to builtin documentation, so it may be preferable to just link to the typing page rather than move the text. But since the old generics are deprecated, if they are removed, the documentation must be preserved.
msg403092 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-10-03 14:56
I think we should go ahead and duplicate the documentation in collections.abc (and in a few other places -- PEP 585 lists some builtins, some in contextlib, some in re). Then we won't have to worry about what happens when the typing module is slimmed down (presumably it will have to remain for things like Any, TypeVar, Generic).
msg403104 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-10-03 18:03
Where are capabilities like "list[str]" and "dict[str, list[int]]" going to be documented?
msg403107 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-10-03 18:27
> Where are capabilities like "list[str]" and "dict[str, list[int]]" going to be documented?

I think those should go with the individual types as well. AFter all, it's specific to the type how many parameters it has and what they mean. There should probably also be a general section explaining these generics, and the individual types can link to those so they don't have to repeat the same background information.
msg403135 - (view) Author: Ken Jin (kj) * (Python committer) Date: 2021-10-04 13:27
> I think those should go with the individual types as well

The list[] and dict[] stdtypes are in a different document from collections.abc.*. While this helps logical separation, I feel like it'd be tougher searching for type information compared to our current aggregate-everything-in-typing approach.

Where type hints for types should belong has been a hot subject for some time. This was discussed at the typing summit, and also by the docs WG.

- Docs WG: https://github.com/python/docs-community/issues/8
- Downstream typing possible tutorial: https://github.com/python/typing/issues/891
- Downstream typing's docs: https://github.com/python/typing/tree/master/docs

The general consensus it seems is to separate complex information from the CPython docs. I like this approach because type hints have zero meaning to CPython, so placing them in docs meant for runtime behavior feels strange.

OTOH, external docs won't be able to keep up with the subtleties of multiple different versions of typing in CPython. So *some* information should be kept in CPython docs.

I think for now, a link in collections.abc pointing to typing would suffice. In the future when Python 3.9 becomes an "old" version and PEP 585 notation is commonplace, we should copy them over like Guido suggested (and if Raymond is OK with collections.abc docs including that sort of information). Guido or Raymond may have other plans though ;-).
msg403144 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-10-04 16:01
I'm not against additional tutorial for typing. But the standard library manual is supposed to be a complete reference. There is enough variation between different generic types (e.g. are the parameters covariant?) that ought to be documented. I don't want to create a "typing ghetto" where all typing information is collected as if it wasn't really part of the language.
History
Date User Action Args
2022-04-11 14:59:50adminsetgithub: 89515
2021-10-08 20:33:32terry.reedysetstage: needs patch
versions: + Python 3.11
2021-10-04 16:01:16gvanrossumsetmessages: + msg403144
2021-10-04 13:27:19kjsetmessages: + msg403135
2021-10-03 18:27:58gvanrossumsetmessages: + msg403107
2021-10-03 18:03:38rhettingersetmessages: + msg403104
2021-10-03 14:56:54gvanrossumsetmessages: + msg403092
2021-10-03 13:19:34kjsetnosy: + gvanrossum, rhettinger, stutzbach, kj
2021-10-03 13:12:33pxegercreate