From b762a36aaa5f963876dc31cf4bf350f530db1e2a Mon Sep 17 00:00:00 2001 From: Johan Karlberg Date: Tue, 31 Mar 2026 09:51:53 +0200 Subject: [PATCH 1/2] fix: start-after/end-before order in _rst_include_trim * Added change log entry --- CHANGELOG.md | 1 + pdoc/docstrings.py | 4 ++-- test/test_docstrings.py | 8 ++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1458ef18..863dd403 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ## Unreleased: pdoc next +- Fix incorrect ordering of `start-after`/`end-before` in RST include directives. - Support Pydantic [`computed_field`](https://docs.pydantic.dev/2.0/usage/computed_fields/) descriptions ([#855](https://github.com/mitmproxy/pdoc/pull/855), @avhz) ## 2025-10-27: pdoc 16.0.0 diff --git a/pdoc/docstrings.py b/pdoc/docstrings.py index 9d45e209..4577c783 100644 --- a/pdoc/docstrings.py +++ b/pdoc/docstrings.py @@ -408,10 +408,10 @@ def _rst_include_trim(contents: str, options: dict[str, str]) -> str: if i := options.get("start-line"): lines = lines[int(i) :] contents = "\n".join(lines) - if x := options.get("end-before"): - contents = contents[: contents.index(x)] if x := options.get("start-after"): contents = contents[contents.index(x) + len(x) :] + if x := options.get("end-before"): + contents = contents[: contents.index(x)] return contents diff --git a/test/test_docstrings.py b/test/test_docstrings.py index 658d4d0d..c03ea860 100644 --- a/test/test_docstrings.py +++ b/test/test_docstrings.py @@ -81,6 +81,14 @@ def test_rst_include_trim_pattern(): assert trimmed == "\ncharlie\ndelta\n" +def test_rst_include_trim_start_after_applied_first(): + content = 'alpha\n"""\nbeta\ncharlie\ndelta\n"""\necho' + trimmed = docstrings._rst_include_trim( + content, {"start-after": '"""\n', "end-before": '"""'} + ) + assert trimmed == "beta\ncharlie\ndelta\n" + + def test_rst_include_trim_mixture(): content = "alpha\nbeta\ncharlie\ndelta\necho" trimmed = docstrings._rst_include_trim( From a635ebbf920e1d0b4426128b88a1434812d5f68e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 13 Apr 2026 11:26:22 +0000 Subject: [PATCH 2/2] [autofix.ci] apply automated fixes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 863dd403..d64bb2a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ## Unreleased: pdoc next - Fix incorrect ordering of `start-after`/`end-before` in RST include directives. + ([#876](https://github.com/mitmproxy/pdoc/pull/876), @JohanKarlbergg) - Support Pydantic [`computed_field`](https://docs.pydantic.dev/2.0/usage/computed_fields/) descriptions ([#855](https://github.com/mitmproxy/pdoc/pull/855), @avhz) ## 2025-10-27: pdoc 16.0.0