Skip to content

Commit 00e18eb

Browse files
fix: start-after/end-before order in _rst_include_trim (#876)
1 parent 72ea209 commit 00e18eb

3 files changed

Lines changed: 12 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
## Unreleased: pdoc next
66

7+
- Fix incorrect ordering of `start-after`/`end-before` in RST include directives.
8+
([#876](https://github.com/mitmproxy/pdoc/pull/876), @JohanKarlbergg)
79
- Support Pydantic [`computed_field`](https://docs.pydantic.dev/2.0/usage/computed_fields/) descriptions ([#855](https://github.com/mitmproxy/pdoc/pull/855), @avhz)
810

911
## 2025-10-27: pdoc 16.0.0

pdoc/docstrings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,10 @@ def _rst_include_trim(contents: str, options: dict[str, str]) -> str:
408408
if i := options.get("start-line"):
409409
lines = lines[int(i) :]
410410
contents = "\n".join(lines)
411-
if x := options.get("end-before"):
412-
contents = contents[: contents.index(x)]
413411
if x := options.get("start-after"):
414412
contents = contents[contents.index(x) + len(x) :]
413+
if x := options.get("end-before"):
414+
contents = contents[: contents.index(x)]
415415
return contents
416416

417417

test/test_docstrings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ def test_rst_include_trim_pattern():
8181
assert trimmed == "\ncharlie\ndelta\n"
8282

8383

84+
def test_rst_include_trim_start_after_applied_first():
85+
content = 'alpha\n"""\nbeta\ncharlie\ndelta\n"""\necho'
86+
trimmed = docstrings._rst_include_trim(
87+
content, {"start-after": '"""\n', "end-before": '"""'}
88+
)
89+
assert trimmed == "beta\ncharlie\ndelta\n"
90+
91+
8492
def test_rst_include_trim_mixture():
8593
content = "alpha\nbeta\ncharlie\ndelta\necho"
8694
trimmed = docstrings._rst_include_trim(

0 commit comments

Comments
 (0)