Expand description
The py domain: object and module registration with Sphinx’s
duplicate semantics — PythonDomain.note_object / note_module /
clear_doc / merge_domaindata
(sphinx/domains/python/__init__.py:780-832 and :744-757) — and the
resolution half: find_obj / resolve_xref (:855-994) plus the
builtin_resolver missing-reference listener (:1077-1098).
Registrations replay from the parse layer’s records
(crate::rst::RegistryExport::py_objects/py_modules) inside
crate::env::std_domain::process_doc’s parse-time pass: in Sphinx
every one of these calls fires while the directive runs, so a
document’s py duplicate warnings interleave with its std
description/term duplicates in document order — probe-verified against
sphinx 9.1.0 (a doc with an envvar duplicate at line 8, a py duplicate
at line 15 and a term duplicate at line 18 warns 8 → 15 → 18).
PythonDomain defines no process_doc hook at all, so the py
slot of _DomainsContainer._process_doc (dispatch order c, changeset, citation, cpp, index, js, math, py, rst, std) contributes nothing of
its own.
Structs§
- Modindex
Entry - One py-modindex row — Sphinx’s 7-field
IndexEntryNamedTuple (sphinx/domains/_index.py:17-52).subtype: 0 = top-level module, 1 = group head (a parent with listed submodules — possibly a dummy with every other field empty), 2 = submodule. - Modindex
Group - One first-letter group of the module index.
- PyDomain
Data - Python-domain (
py) registries:domaindata['py']['objects']and['modules']. - PyModindex
PythonModuleIndex.generate()’s(sorted_content, collapse).- PyModule
Entry - Sphinx’s
ModuleEntry(__init__.py:67-73), keyed by module name inPyDomainData::modules. - PyObject
Entry - Sphinx’s
ObjectEntry(__init__.py:60-65), keyed by fullname inPyDomainData::objects. - PyXref
Target - A resolved py cross-reference: what the resolver needs to build the
referencenodemake_refnode/_make_module_refnodewould.
Functions§
- builtin_
resolver builtin_resolver(__init__.py:1077-1098), the py domain’s missing-reference listener at priority 900 — AFTER intersphinx’s default-priority (500) handler, so a builtin name that a loaded inventory carries resolves externally instead of being silenced (probe::py:class:intwith `int` in a mapped inventory renders the external reference; `:py:class:`bool, absent from it, is silenced).- find_
obj PythonDomain.find_obj(__init__.py:855-928): find candidates forname, perhaps using the given module/class context. Returns(fullname, entry)pairs in match order.- generate_
modindex PythonModuleIndex.generate(__init__.py:628-717), verbatim:modindex_common_prefixsorted longest-first (stable, so equal lengths keep config order); modules sorted bylower()(stable over registration order); the FIRST matching prefix is stripped (and restored when it swallowed the whole name, clearingstripped); letter buckets key on the first character of the stripped name, lowercased; a submodule (package != modnameon the stripped name) gets subtype 2, promoting the bucket’s previous entry to a group head when it IS the parent, or inserting an all-empty dummy parent when noprev_modname.startswith(package)entry preceded it; display names keep the stripped prefix (stripped + modname);collapseiff submodules outnumber top-levels; groups come out letter-sorted.- modindex_
snapshot - The
py_modindexslice of the environment snapshot, mirroringcrate::env::genindex::snapshot’s serde shape. - resolve_
any_ xref PythonDomain.resolve_any_xref(__init__.py:996-1037): alwaysfind_obj(..., type=None, searchmode=1); when there are several matches, aliased entries are skipped; a module match yields('py:mod', module_refnode), everything else('py:' + role_for_objtype(objtype), refnode)— infind_obj’s match order, which is what the generic any-resolver’s first-wins rule and its ambiguity candidate list run on.- resolve_
xref PythonDomain.resolve_xrefminus the node plumbing (:930-994): the type-fallback retries, the ambiguity rule, and the module/object split. Returns the target (None = dangling, silent here — the warning is the resolver’s) and the ambiguity warning to log,type='ref', subtype='python'→[ref.python], which fires even on a successful resolution.