chore: guard against Sphinx/RST markup returning to docstrings - #1913
Merged
Merged
Conversation
Follow-up to #1910, which converted Sphinx roles, directives and literal- block markers in docstrings to their Markdown/Google equivalents. The docs site renders docstrings through mkdocstrings with the Google parser, which treats them as Markdown, so RST markup leaks through verbatim onto the published API pages. Add two pygrep pre-commit hooks so it does not creep back: - no-rst-roles: `:class:`/`:meth:`/`:func:`/`:mod:`/`:attr:`/`:data:`/ `:exc:`/`:obj:`/`:ref:` roles and `.. directive::` lines. - no-rst-literal-blocks: the trailing `::` literal-block marker. Both are scoped to `^packages/[^/]+/src/.*\.py$`. Test docstrings still use RST roles and are never rendered, so widening the scope would only produce noise. Verified: both hooks pass on the current tree, and against the pre-#1910 copy of _entities_service.py they report 69 and 66 offending lines respectively. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
Both guards can be bypassed by valid whitespace variations.
Review effort: Lite
Findings: None
What changed in this PR
Adds scoped pre-commit checks to prevent Sphinx/RST markup from returning to rendered source docstrings.
Changes:
- Detects RST roles and directives.
- Detects trailing
::literal-block markers. - Limits checks to package source files.
The directive pattern should allow arbitrary whitespace, and the literal-block pattern should allow trailing spaces.
| File | Description |
|---|---|
.pre-commit-config.yaml |
Adds scoped pygrep hooks for RST syntax detection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
gheorghitahurmuz
approved these changes
Sep 28, 2026
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Follow-up to #1910 (merged), which converted the Sphinx roles, directives and literal-block markers in our docstrings to their Markdown/Google equivalents.
Implements @gheorghitahurmuz's review suggestion on that PR.
Why
The docs site renders docstrings through mkdocstrings with the Google parser, which treats them as Markdown. RST markup therefore leaks through verbatim onto the published API pages — which is exactly how #1910 started, with
:meth:retrieve_v3`` andBasic usage::visible on https://uipath.github.io/uipath-python/core/entities/. Nothing currently stops it coming back.Change
Two
pygrephooks in.pre-commit-config.yaml:no-rst-roles:class::meth::func::mod::attr::data::exc::obj::ref:roles, and.. directive::linesno-rst-literal-blocks::literal-block markerTwo deltas from the suggested snippet, both easy to drop if you'd rather not:
refto the role alternation — same family, and docs: render docstring cross-references as Markdown, not Sphinx RST #1910 stripped those too.::. That was the third RST-ism docs: render docstring cross-references as Markdown, not Sphinx RST #1910 fixed (Basic usage::rendered with a stray extra colon), and it is the one most likely to be reintroduced by muscle memory.Both are scoped to
^packages/[^/]+/src/.*\.py$exactly as suggested. That scope is load-bearing, not incidental: test docstrings still use RST roles, and since they are never rendered, #1910 deliberately left them alone — widening the scope would fail immediately on them.Verification
_entities_service.py, they fail with 69 and 66 offending lines respectively — i.e. they would have caught the original bug.\.\. [a-z-]+::in case pre-commit shlex-split the entry and silently dropped the directive half. It does not:pygrep.run_hookbuildscmd = (sys.executable, '-m', __name__, *args, entry), passingentryas a single argv element. Confirmed empirically against a directive-only probe file, so the pattern is used verbatim.One unrelated note:
pre-commit run --all-filesalso failsruff/ruff-formaton six files under.github/scripts/. That drift is pre-existing onmain(verified) and untouched here.🤖 Generated with Claude Code