| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
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 overview4 files changed ± howto/a-conceptual-overview-of-asyncio.html ± library/types.html ± whatsnew/3.10.html ± whatsnew/3.15.html |
Sorry, something went wrong.
|
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. |
Sorry, something went wrong.
|
Backward-compatibility check.
This resolves more references than it breaks. |
Sorry, something went wrong.
|
That distinction is real at the implementation level: types re-exports type objects defined in C rather than defining them itself. The difficulty is that the same file already documents C-defined type objects with .. class::: CodeType, ModuleType, TracebackType, MappingProxyType, GenericAlias, UnionType, and CapsuleType. None of those are defined in types.py either; they are C type objects exposed as names, the same as FunctionType or FrameType. So "defined in C" does not separate the current .. data:: entries from the .. class:: ones. The split that does hold is whether a constructor signature is shown, and UnionType / CapsuleType are .. class:: without one. The directive also drives cross-referencing rather than provenance. inspect.isclass() is true for all of these, and CPython's own C-API docs already reference them with :class: — for example Doc/c-api/descriptor.rst (GetSetDescriptorType, MemberDescriptorType, MethodDescriptorType, WrapperDescriptorType), Doc/c-api/frame.rst (FrameType), and Doc/c-api/gen.rst (AsyncGeneratorType) — which is why those links do not resolve today. Downstream, Sphinx itself maps these to their types.* name and renders them as classes in _INVALID_BUILTIN_CLASSES, so autodoc emits class references to them regardless of the directive used here. Other projects keep their own copy of that table, for example npdoc2md and quicktile. What criterion would you want applied? If "type objects re-exported from C should be .. data::", then CodeType / ModuleType / TracebackType / UnionType / CapsuleType fall under it too and should move back for consistency. If "documented as a class when it is a class", the remaining .. data:: entries are the ones out of step. Either way works for me; I would just like the file to end up internally consistent. |
Sorry, something went wrong.
|
Urgh ok, let'd use class everywhere. It will solve future issues. It may also solve issues with autodoc in general. |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. 👍
Sorry, something went wrong.
|
Thanks @gaborbernat for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
Sorry, something went wrong.
|
Sorry, @gaborbernat and @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict. cherry_picker bc055444e4ade9e210139d07200f602a4a9feb67 3.14 |
Sorry, something went wrong.
|
GH-150761 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
Sorry, @gaborbernat and @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict. cherry_picker bc055444e4ade9e210139d07200f602a4a9feb67 3.13 |
Sorry, something went wrong.
|
Please don't forget about backports. |
Sorry, something went wrong.
|
GH-153757 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
|
GH-153758 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The types module exposes built-in type objects (FunctionType, LambdaType, MethodType, the descriptor type family, FrameType, CoroutineType, AsyncGeneratorType, and the newer FrameLocalsProxyType / 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 in Doc/c-api/descriptor.rst, Doc/c-api/frame.rst, Doc/c-api/gen.rst, Doc/c-api/structures.rst, Doc/library/inspect.rst, and several Doc/whatsnew/ pages.
This switches those entries to .. class::, matching how UnionType, CapsuleType, CodeType, and ModuleType are 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, and EllipsisType are handled in a separate PR.
Refs: gh-89554 (reported in 2021; UnionType was fixed then in GH-28757, the remainder left open). Documentation-only change, so no Misc/NEWS entry (skip news).
cc @AA-Turner as the Lib/types.py maintainer.