Skip to content

API docs: hide +HIDE doctest setup, drop duplicate modifier badge#65

Merged
tony merged 4 commits into
mainfrom
doctest-hide-badges
Jul 14, 2026
Merged

API docs: hide +HIDE doctest setup, drop duplicate modifier badge#65
tony merged 4 commits into
mainfrom
doctest-hide-badges

Conversation

@tony

@tony tony commented Jul 14, 2026

Copy link
Copy Markdown
Member

Two independent API-documentation polish features (one PR, two commits).

1. Hide # doctest: +HIDE examples from render (typehints-gp)

_strip_hidden_doctest_examples(lines), called first in process_docstring, drops each >>> line carrying # doctest: +HIDE plus its ... continuations from the rendered docstring. The doctest runner reads __doc__ from source, so the example still executes as a test — only the rendered docs lose the incidental setup (an env mapping, a socket path).

Pairs with the gp-libs HIDE optionflag registration (git-pull/gp-libs#79), which lets the marker parse instead of raising ValueError: invalid option.

2. Drop the modifier prefix duplicated by the badge (api-style)

A classmethod/staticmethod/async/abstract member rendered its modifier twice: once as the left signature prefix, once as the badge. _strip_redundant_prefix(sig_node) removes the leading desc_sig_keyword whose text is in _KEYWORD_TO_MOD, keyed off that same map so detection and stripping never drift. Type-word prefixes (property/type) are left untouched.

Tests

Both helpers carry module doctests (run via --doctest-modules); the existing api_style snapshot suite still passes unchanged.

tony added 2 commits July 13, 2026 19:31
why: A docstring often needs incidental setup (building an env mapping, a
socket path) so its example executes, but that plumbing is noise to the
reader. The doctest runner reads __doc__ from source, so rewriting the
rendered docstring hides setup from the docs without affecting the test.

what:
- Add _strip_hidden_doctest_examples(lines), called first in
  process_docstring (before NumPy conversion).
- Drop each `>>>` line carrying `# doctest: +HIDE` plus its `...`
  continuation lines. Covered by a module doctest.
why: A classmethod/staticmethod/async/abstract member rendered its
modifier twice — once as the left signature prefix, once as the badge.

what:
- Add _strip_redundant_prefix(sig_node); call it from _inject_badges after
  modifier detection and slot injection.
- Remove leading desc_sig_keyword nodes whose text is in _KEYWORD_TO_MOD
  (async/classmethod/static/abstract/abstractmethod/final) plus the
  trailing space; drop the annotation if it empties out.
- Keyed off _KEYWORD_TO_MOD so detection and stripping never drift.
  Type-word prefixes (property/type) are left untouched. Covered by a
  module doctest.
@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.55172% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.65%. Comparing base (fc5833f) to head (641a3ba).

Files with missing lines Patch % Lines
...ts-gp/src/sphinx_autodoc_typehints_gp/extension.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #65   +/-   ##
=======================================
  Coverage   92.64%   92.65%           
=======================================
  Files         273      273           
  Lines       21491    21520   +29     
=======================================
+ Hits        19911    19939   +28     
- Misses       1580     1581    +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

tony added a commit to tmux-python/libtmux that referenced this pull request Jul 14, 2026
why: The socket_path/env plumbing that opens each from_env example is
needed for the doctest to execute but is noise to the reader. Marking it
hidden runs it as a test while keeping it out of the rendered docs.

what:
- Tag the setup lines in Server/Window/Pane.from_env with
  `# doctest: +HIDE`; split the env dicts so the marker fits <=88 cols.
- Session.from_env hides only socket_path — its env carries the
  deliberately wrong session id the surrounding prose explains, so it
  stays visible (hide plumbing, not meaning).
- TEMP: pin gp-libs / gp-sphinx to the branches carrying the HIDE
  optionflag and the render strip (git-pull/gp-libs#79,
  git-pull/gp-sphinx#65) via [tool.uv.sources]; revert to releases once
  they land.
@tony tony changed the title API docs: hide +HIDE doctest setup, drop duplicate modifier badge API docs: hide +HIDE doctest setup, drop duplicate modifier badge Jul 14, 2026
tony added a commit to tmux-python/libtmux that referenced this pull request Jul 14, 2026
why: The socket_path/env plumbing that opens each from_env example is
needed for the doctest to execute but is noise to the reader. Marking it
hidden runs it as a test while keeping it out of the rendered docs.

what:
- Tag the setup lines in Server/Window/Pane.from_env with
  `# doctest: +HIDE`; split the env dicts so the marker fits <=88 cols.
- Session.from_env hides only socket_path — its env carries the
  deliberately wrong session id the surrounding prose explains, so it
  stays visible (hide plumbing, not meaning).
- TEMP: git-branch-pin the three changed packages (gp-libs,
  sphinx-autodoc-api-style, sphinx-autodoc-typehints-gp) to
  doctest-hide-badges; add typehints-gp as a direct dep so uv honors its
  source pin (uv.sources applies to direct deps only). gp-sphinx and its
  JS-asset packages stay on PyPI wheels, so CI needn't build the
  vite/pnpm toolchain. Revert to releases once git-pull/gp-libs#79 and
  git-pull/gp-sphinx#65 publish.
tony added 2 commits July 13, 2026 20:08
why: The branch taught the extension to drop +HIDE-flagged doctest
setup from rendered docstrings, but nothing told authors how to reach
for it or that the flag must be registered to keep running as a test.

what:
- Add a "Hiding incidental doctest setup" how-to section: illustrative
  before/after plus the build-time-strip vs test-time-run distinction.
- Add a Features bullet so the capability is discoverable.
- Name the doctest.register_optionflag("HIDE") prerequisite and the
  ValueError an unregistered flag raises.
why: Record the user-visible behavior this branch introduces as a
merge-ready roll-up under the unreleased section.

what:
- Add What's new entry: +HIDE-tagged doctest lines still run but drop
  from rendered autodoc output.
- Add Fixes entry: api-style modifier no longer renders twice (prefix
  plus badge) for classmethod/staticmethod/async/abstract members.
@tony tony force-pushed the doctest-hide-badges branch from fc9df84 to 641a3ba Compare July 14, 2026 01:08
@tony tony merged commit c18f832 into main Jul 14, 2026
44 checks passed
@tony tony deleted the doctest-hide-badges branch July 14, 2026 02:08
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 participants