gh-89554: Document standard type objects in types as classes#150676
gh-89554: Document standard type objects in types as classes#150676gaborbernat wants to merge 1 commit into
Conversation
The type objects exposed by the types module (FunctionType, MethodType, the descriptor type family, FrameType and others) are classes, but were documented with the ".. data::" directive. As a result existing ":class:`types.X`" cross-references, such as those in the C API docs for descriptors, frames, generators and structures, and in inspect and the What's New pages, fail to resolve against a py:class target. Switch these entries to ".. class::", matching the existing treatment of UnionType, CapsuleType, CodeType and ModuleType in the same file, and update the handful of ":data:" references accordingly so nothing breaks in the other direction. The singleton-value types NoneType, NotImplementedType and EllipsisType are left as ".. data::" for now, since they are referenced as the type of a singleton value (:data:) and warrant a separate discussion.
Documentation build overview
4 files changed± howto/a-conceptual-overview-of-asyncio.html± library/types.html± whatsnew/3.10.html± whatsnew/3.15.html |
|
Those are actually real data, not classes. The objects are not defined in those modules, but in C and therefore there is a distinction between them. |
|
Backward-compatibility check.
This resolves more references than it breaks. |
|
That distinction is real at the implementation level: The difficulty is that the same file already documents C-defined type objects with The directive also drives cross-referencing rather than provenance. What criterion would you want applied? If "type objects re-exported from C should be |
|
Urgh ok, let'd use class everywhere. It will solve future issues. It may also solve issues with autodoc in general. |
The
typesmodule exposes built-in type objects (FunctionType,LambdaType,MethodType, the descriptor type family,FrameType,CoroutineType,AsyncGeneratorType, and the newerFrameLocalsProxyType/LazyImportType). These are classes, but the documentation marks them with the.. data::directive, so existing:class:cross-references to them resolve against a missing py:class target and fail. Affected references appear inDoc/c-api/descriptor.rst,Doc/c-api/frame.rst,Doc/c-api/gen.rst,Doc/c-api/structures.rst,Doc/library/inspect.rst, and severalDoc/whatsnew/pages.This switches those entries to
.. class::, matching howUnionType,CapsuleType,CodeType, andModuleTypeare already documented in the same file, and updates the few:data:references to:class:so nothing breaks in the other direction.The singleton-value types
NoneType,NotImplementedType, andEllipsisTypeare handled in a separate PR.Refs: gh-89554 (reported in 2021;
UnionTypewas fixed then in GH-28757, the remainder left open). Documentation-only change, so noMisc/NEWSentry (skip news).cc @AA-Turner as the
Lib/types.pymaintainer.