You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the note on Sphinx Python name resolution more prominent.
Almost nobody knows that Sphinx normally pays no attention to your
import statements, and I didn't even notice the existing text on this
when I went to add new text on it.
Copy file name to clipboardExpand all lines: restructuredtext/style.rst
+30-6Lines changed: 30 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -356,13 +356,37 @@ Objects can be referenced with these roles:
356
356
- ``:py:data:`pkg.mod.VARIABLE``` to reference a module-level variable ``VARIABLE`` in ``pkg.mod``.
357
357
- ``:py:const:`pkg.mod.CONSTANT``` to reference a module-level *constant* ``CONSTANT`` in ``pkg.mod``.
358
358
359
-
Namespace resolution
360
-
""""""""""""""""""""
359
+
.. note::
360
+
Types in docstrings do *not* respect imports in the file, and instead are resolved using `Sphinx's own target-resolution rules <https://www.sphinx-doc.org/en/master/usage/domains/python.html#target-resolution>`__.
361
+
In other words,
362
+
363
+
.. code-block::
364
+
365
+
from collections.abc import Sequence
366
+
367
+
def run_stuff(stuff):
368
+
"""Run some stuff.
369
+
370
+
Parameters
371
+
----------
372
+
stuff : `Sequence` [`str`]
373
+
Stuff to run.
374
+
375
+
does not work, but
376
+
377
+
.. code-block::
378
+
379
+
from collections.abc import Sequence
380
+
381
+
def run_stuff(stuff):
382
+
"""Run some stuff.
383
+
384
+
Parameters
385
+
----------
386
+
stuff : `~collections.abc.Sequence` [`str`]
387
+
Stuff to run.
361
388
362
-
In these examples, the full namespace of each Python object is specified.
363
-
In some contexts, Sphinx may be able to identify the reference object without the full namespace.
364
-
For example in class docstrings, references to methods or attributes in the same class can be made by name alone.
365
-
See the `Sphinx documentation <http://sphinx-doc.org/domains.html#cross-referencing-python-objects>`_ for more details on object resolution.
389
+
does. See the link above for how to make relative links to types; the syntax is not the same as Python's, and it operates on the documentation hierarchy, not the module hierarchy.
0 commit comments