Skip to content

gh-150319: Replace all documentation which says "See PEP 585"#150325

Open
sirosen wants to merge 3 commits into
python:mainfrom
sirosen:improve-all-see-pep-585-docstrings
Open

gh-150319: Replace all documentation which says "See PEP 585"#150325
sirosen wants to merge 3 commits into
python:mainfrom
sirosen:improve-all-see-pep-585-docstrings

Conversation

@sirosen
Copy link
Copy Markdown
Contributor

@sirosen sirosen commented May 23, 2026

This is a documentation update touching many modules, eliminating text which says "See PEP 585".
The general phrasing used is "X is generic over Y", and this is kept consistent as much as possible.
We can use different phrasing; the goal here is to be consistent in whatever we choose.

For types visible in the stdlib, documentation is also lifted up into class-level docs.
For builtins, however, the story for documenting this is in many cases more complex.
Therefore, updates to the doc pages are omitted for now.


The following classes in the stdlib get simple updates:

  • array.array
  • asyncio.Future
  • asyncio.Task
  • collections.defaultdict
  • collections.deque
  • contextvars.ContextVar
  • contextvars.Token
  • ctypes.Array
  • os.DirEntry
  • re.Match
  • re.Pattern
  • string.templatelib.Interpolation
  • string.templatelib.Template
  • types.MappingProxyType
  • queue.SimpleQueue
  • weakref.ref

The following classes are documented publicly as functions, and are therefore updated internally (__class_getitem__.__doc__) but not in the public docs:

  • functools.partial
  • itertools.chain

The following builtin types have updates to __class_getitem__.__doc__ but not to any documentation pages:

  • BaseExceptionGroup
  • coroutines (from generators)
  • dict
  • enumerate
  • frozendict
  • frozenset
  • generators (and async generators)
  • list
  • memoryview
  • set
  • slice
  • tuple

Special cases:

  • union objects are now documented as "supporting class-level []", rather than anything to do with generics.

  • Templates might be generic over a single type (union, in theory) or over a TypeVarTuple. As this is not currently fully settled, it is marked with a comment and a mild hint that it is a single type is used
    (namely, "type" is singular rather than "types", plural)


Additional issues resolved:

The following classes in the stdlib get simple updates:

- array.array
- asyncio.Future
- asyncio.Task
- collections.defaultdict
- collections.deque
- contextvars.ContextVar
- contextvars.Token
- ctypes.Array
- os.DirEntry
- re.Match
- re.Pattern
- string.templatelib.Interpolation
- string.templatelib.Template
- types.MappingProxyType
- queue.SimpleQueue
- weakref.ref

The following classes are documented publicly as functions, and are
therefore updated internally (`__class_getitem__.__doc__`) but not in the
public docs:

- functools.partial
- itertools.chain

The following builtin types have updates to `__class_getitem__.__doc__`
but not to any documentation pages:

- BaseExceptionGroup
- coroutines (from generators)
- dict
- enumerate
- frozendict
- frozenset
- generators (and async generators)
- list
- memoryview
- set
- slice
- tuple

Special cases:

- union objects are now documented as "supporting class-level []",
  rather than anything to do with generics.

- Templates might be generic over a single type (union, in theory) or
  over a TypeVarTuple. As this is not currently fully settled, it is
  marked with a comment and a mild hint that it is a single type is used
  (namely, "type" is singular rather than "types", plural)
@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented May 23, 2026

Comment thread Doc/library/string.templatelib.rst Outdated
template.strings: ('Ah! We do have ', '.')
template.values: ( 'Camembert', )

Templates are :ref:`generic <generics>` over the type of the values which
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.

Template is actually not generic in typeshed at the moment. There has been some low-level discussion about whether and how they should be generic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Given that there's debate about how it should work, I can strike this line. But what should I put in the docstring for it? Maybe just Template supports []?

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.

Yes, I'd remove the line from the RST docs and put something noncommittal in the __class_getitem__ docstring.

Comment thread Objects/genobject.c Outdated
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("generators are generic over the type of their values")},
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.

They are actually generic over three type variables (yield, send, and return type).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yes! I often see these given as None. I'll fix.

Comment thread Objects/genobject.c Outdated
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("coroutines are generic over the type of their return value")},
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.

Also three typevars: yield, send, and return. (Though in practice the first two are usually given as Any and I'm not sure they have much practical use.)

Comment thread Objects/genobject.c Outdated
{"__sizeof__", gen_sizeof, METH_NOARGS, sizeof__doc__},
{"__class_getitem__", Py_GenericAlias,
METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
METH_O|METH_CLASS, PyDoc_STR("async generators are generic over the type of their values")},
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.

Two typevars: yield and send.

Comment thread Objects/setobject.c Outdated
Comment thread Objects/sliceobject.c Outdated
{"__reduce__", slice_reduce, METH_NOARGS, reduce_doc},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, "See PEP 585"},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
"slices are generic over the type of their values"},
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.

In typeshed they are generic over three typevars, for start, end, and step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof! I've made more mistakes than I wanted in this PR. Thanks for all the good catches.

Comment thread Objects/tupleobject.c Outdated
TUPLE_COUNT_METHODDEF
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS, PyDoc_STR("See PEP 585")},
{"__class_getitem__", Py_GenericAlias, METH_O|METH_CLASS,
PyDoc_STR("tuples are generic over the types of their contents, with type arguments which match the types and arity of their contents")},
Copy link
Copy Markdown
Member

@JelleZijlstra JelleZijlstra May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use a longer explanation, mentioning the use of tuple[T, ...] for arbitrary-length tuples and tuple[A], tuple[A, B] etc., for fixed-length tuples.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think I'll break it out into a PyDoc_STRVAR so that I can make it more legible in that case.

Comment thread Objects/unionobject.c Outdated
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@JelleZijlstra
Copy link
Copy Markdown
Member

Also, any reason you didn't add any wording to the documentation for the builtin generic classes (list etc.)?

And expand the text for tuples.

Co-authored-by: Jelle Zijlstra <906600+JelleZijlstra@users.noreply.github.com>
@sirosen
Copy link
Copy Markdown
Contributor Author

sirosen commented May 24, 2026

I pushed the corrections in a co-authored commit, along with

  • expanded the doc for tuple
  • made the doc for Template really barebones

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify what memoryview is generic in Links to PEP 585 in Generic types

2 participants