Skip to content

Fix Sphinx cross-reference warnings#1177

Open
zain-asif-dev wants to merge 2 commits into
gorakhargosh:masterfrom
zain-asif-dev:fix/sphinx-reference-warnings
Open

Fix Sphinx cross-reference warnings#1177
zain-asif-dev wants to merge 2 commits into
gorakhargosh:masterfrom
zain-asif-dev:fix/sphinx-reference-warnings

Conversation

@zain-asif-dev

Copy link
Copy Markdown

Description

Fixes the reference target not found warnings reported when building the documentation.

  • Enabled sphinx.ext.intersphinx and mapped it to the Python standard library docs, so references to types like pathlib.Path, logging.Logger, re.Pattern, etc. resolve.
  • Corrected several docstring cross-references that used a bare class or method name where a fully qualified name is required for the reference to resolve wherever the docstring is rendered. In particular, FileSystemEventHandler.on_any_event (and similar methods) are inherited without their own docstring by classes in watchdog.tricks, so a bare :class:FileSystemEvent`` in the base docstring fails to resolve once it is rendered under a different module.
  • Added docstrings to DirectorySnapshot.isdir, mtime, and size, which were referenced from another docstring but were otherwise undocumented, and fixed :func: roles that should have been :meth:.
  • Fixed a reference to Observer.schedule in quickstart.rst to point at the method's actual defining class, BaseObserver.

A few references can never be resolved and are listed in nitpick_ignore with an explanation:

  • A type hint that shows up unqualified (Path) because annotations are stored as strings due to from __future__ import annotations.
  • watchdog.utils.bricks.SkipRepeatsQueue, an internal base class that isn't part of the public, documented API.
  • The platform specific observer implementations (inotify.InotifyObserver, fsevents.FSEventsObserver, kqueue.KqueueObserver, read_directory_changes.WindowsApiObserver), since only one of these can ever be importable on a given platform.

Fixes #898

Testing

  • tox -e docs (runs sphinx-build -aEWb html docs/source docs/build/html, which now succeeds with zero warnings)
  • python -m sphinx -n -T -b man docs/source <outdir> (nitpicky mode) also succeeds with zero warnings
  • pytest (full suite): 170 passed, 10 skipped, 2 xpassed

Enable sphinx.ext.intersphinx so references to standard library types
resolve correctly, and correct several docstring cross-references that
used bare class or method names where a fully qualified name was
required to resolve in the context the docstring ends up being
rendered in (including cases where a docstring is inherited by a
subclass defined in a different module). Also add docstrings to a few
DirectorySnapshot methods that were referenced but previously
undocumented.

The remaining handful of references that can never be resolved (a
type hint that is only available unqualified due to postponed
evaluation of annotations, an internal base class that is not part of
the public API, and the platform specific observer implementations
that can only be imported on their own platform) are listed in
nitpick_ignore with an explanation.

Signed-off-by: Zain Asif <zainasif.jutt1@gmail.com>
@BoboTiG

BoboTiG commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

That's nice, thanks @zain-asif-dev.

Could you also add a CI job to catch future regressions?

Signed-off-by: Zain Asif <zainasif.jutt1@gmail.com>
@zain-asif-dev

Copy link
Copy Markdown
Author

Good idea. The existing docs CI job already runs sphinx-build with -W (warnings as errors), but not in nitpicky mode (-n), and it turns out these particular reference warnings are only emitted in nitpicky mode. Without -n, sphinx-build silently renders unresolvable :class:/:meth: references as plain text instead of warning, so the previous CI wouldn't have caught this regression (or future ones).

Added -n to the existing sphinx-build command in tox.ini so the current "Build the documentation" CI step now catches this. Verified it fails with 37 warnings on the code before this PR's fix, and passes cleanly with it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2.1.9: sphinx warnings reference target not found

2 participants