Repository navigation
chore(lint): flag new rST markup in non-rendered docstrings - #21010
dd-apm-ecosystems[bot] wants to merge 2 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 804a915 | Docs | View more details | Give us feedback! |
There was a problem hiding this comment.
Shouldn't this be either a CI job too or at least integrated in one? 🤨
There was a problem hiding this comment.
A general question: who owns these scripts? Like, sure, they seem cool and all, but who maintains them? I'm slightly concerned that we may soon be adding a deluge of bespoke, "hand"-rolled scripts where better options exist (proper static analysis/AST Grep/etc.)
There was a problem hiding this comment.
Can you help me add a skill to encourage proper placement of these rules?
Description
Observed in 1 of the ~100+ human-authored PRs reviewed over the past 30 days (PR #19821, reviewed by the automated reviewer
chatgpt-codex-connector[bot], with the fix accepted by the human PR author/maintainerlitianningdatadog): a newly added private-module inline comment used reStructuredText double-backtick literal markup (add_*_metric) even though the comment lives in a non-Sphinx-rendered file. The author replied "Fixed in afe7423: the comment now reads plainadd_*_metric" — a human maintainer explicitly acting on the bot's suggestion by pushing a follow-up commit, which is the acceptance bar this mission requires for bot-originated feedback.This is not a one-off false alarm: the same
chatgpt-codex-connector[bot]review comment pattern ("Use plain prose in the private ... docstring" / "Remove rST markup from the private ... docstring") recurred across at least 15 additional PRs in the same 30-day window (e.g. #20671, #20892, #20917, #20763, #20773, #20615, #20721, #20688, #20716, #20611, #20589, #19771, #20772, #20700, #20935), each time citing the same documented convention inAGENTS.md("Docstrings and Comments": only docstrings Sphinx renders via adocs/*.rst.. automodule::directive use reStructuredText; everything else — private modules,.pyistubs, tests, inline comments — is plain prose). Several of those additional occurrences were likewise fixed by the human PR author in a follow-up commit (e.g. #20892: "Fixed in a3b2181" / "Fixed in 812c585" by a MEMBER; #20917: "Fixed in c50379a"; #20763: "Fixed in a1f0d8e"; #20615: "Fixed in d69c01c"). A single confirmed, maintainer-accepted, mechanically-detectable occurrence would already be sufficient justification per this mission's guardrails — the recurrence across many more PRs in-window is additional supporting evidence that this pattern is both real and worth automating, and likely recurs outside this window too.This is a strong automation candidate: it is purely syntactic (a regex over comment/docstring text, no business logic), has a very low false-positive rate when scoped correctly (see Risks), and is already being caught reliably by a pattern-based AI reviewer — itself a signal that the rule is mechanically well-defined.
No existing lint/CI check covers this:
ruff'spydocstylerules (pyproject.toml) check docstring presence/structure, not rST-vs-prose markup content, and there is no flake8/pylint rule for it either. Rather than introduce a new general-purpose tool, this PR follows the repository's own precedent for this exact kind of policy check —scripts/check_no_new_aidev_anchors.py+.github/workflows/check-no-new-aidev-anchors.yml(a small, diff-scoped Python script wired into a PR-only GitHub Actions workflow) — and adds a sibling script/workflow pair built the same way, since that is the most idiomatic convention already established in this repo for "new-code-only, mechanically-detectable policy" checks.Testing
tests/internal/test_check_no_rst_in_private_docstrings.py, mirroring the existingtests/internal/test_check_no_new_aidev_anchors.pytest style, covering: rendered-module detection via realdocs/*.rst.. automodule::directives,.pyistubs always being treated as non-rendered, the double-backtick regex (including that it does not match 3+ backtick Markdown fences), comment/docstring span extraction viatokenize, and that only added lines are flagged (a line with a pre-existing violation is not flagged if untouched by the diff)."""Does ``x`` thing."""in a private module (ddtrace/internal/...) → correctly flagged.ddtrace/contrib/bottle.py(a Sphinx-automodule'd file) → correctly NOT flagged.tests/*.pytree: confirmed there are ~1171 pre-existing double-backtick occurrences across 210 files today — all of which are correctly ignored by this checker because it only inspects lines added in a diff, confirming it will not break on existing code.ruff format --checkandruff checkagainst both new Python files: clean.Risks
docs/*.rstfile names it directly via.. automodule::. A small number of public classes are documented via.. autoclass::/.. autofunction::instead, while their code physically lives in a private-looking file — e.g.ddtrace.trace.Tracer(defined inddtrace/_trace/tracer.py),ddtrace.trace.Span, andddtrace.propagation.http.HTTPPropagator(all indocs/api.rst). A PR that adds correct rST to one of those specific docstrings would be incorrectly flagged. This does not affect any existing code (only new/changed lines are checked), and is a narrow, enumerable edge case; a reasonable follow-up would teach the script to also resolveautoclass/autofunctiontargets back to their defining file. Noted here rather than silently fixed, per the instruction to keep this change scoped and reviewable.check-no-new-aidev-anchorscheck. It cannot fail on pre-existing code, so there is no risk of blocking unrelated PRs or requiring a repo-wide cleanup.Additional Notes
Local verification:
python scripts/check_no_rst_in_private_docstrings.py --base-ref origin/mainfrom a repo checkout with the target branch checked out. The script requires no extra dependencies beyond the stdlib (tokenize,re,subprocess,argparse).CI integration — IMPORTANT, needs a maintainer action: This automation's GitHub App integration does not hold the
workflowspermission scope, so it could not create.github/workflows/check-no-rst-in-private-docstrings.ymldirectly (GitHub rejects any Contents-API write under.github/workflows/without that scope, 403 "Resource not accessible by integration"). A maintainer needs to add the following file by hand (copy-paste, no changes needed) for this check to actually run in CI; until then, this PR only adds the script and its tests, and the check is not yet wired into the merge-blocking pipeline:This mirrors
.github/workflows/check-no-new-aidev-anchors.ymlexactly (same checkout/setup-python pins, samepull_request-only trigger, samefetch-depth: 0for a reliable merge-base) — only the job name and the invoked script differ.Citations: The accepted bot-originated finding that motivated this change is #19821 (comment) (chatgpt-codex-connector[bot]) with the maintainer's accepting reply at the same thread ("Fixed in afe7423..."). Additional same-pattern, maintainer-accepted occurrences in-window include PR #20892 (#20892 (comment) and #discussion_r4272725723, fixed by MEMBER
elihschiff), #20917 (#20917 (comment), fixed byYun-Kim), #20763 (#20763 (comment), fixed byYun-Kim), and #20615 (#20615 (comment), fixed by MEMBERgnufede).This change has no customer-facing effect (CI-only), so it does not need a release note; please apply the
changelog/no-changeloglabel.