Remove doctest directives from example blocks
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 228
- PR merge metrics
- No merged PRs in 30d
Description
Problem Description
Example blocs inside docstrings can be tested to check they don’t contain mistakes, such special tests are named doctests. Python allows doctests to contain options, passed as directives, to modify the evaluation of the test. By instance:
>>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]
where +ELLIPSIS enables ... to be used as a regex .*, and +NORMALIZE_WHITESPACE makes spaces not accounted for in the evaluation.
Directives are convenient for writing doctests, but are not useful in a documentation.
Proposal
I suggest to filter doctest directives out in the outputed HTML document. Given that directives are always formated as # doctest: <something>, I think it would be fairly easy to identify them with a regex. This behavior could be modified by a pdoc option, such as --keep-doctests-directives.
What do you think?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing pdoc's doctest example handling into the HTML rendering path, using the Python doctest directive format described in the issue. Confirm how directive text is represented before deciding how it should be filtered; done means generated HTML omits directives while preserving the example content, with tests covering the documented example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100