Repository navigation
docs: fix blog code blocks that fail the docs lint - #2587
Closed
hassaanch23 wants to merge 1 commit into
Closed
hassaanch23 wants to merge 1 commit into
hassaanch23 wants to merge 1 commit into
Conversation
`tests/docs/test_posts.py` lints every code block under `docs/blog/posts` with
black via pytest-examples. 34 of them fail on `main`, which is why `weekly-tests`
and the `release` job's test step are both red.
This fixes 16 of the 34. Two were genuinely broken Python -- a reader copying
them gets a SyntaxError:
bad-schemas-could-break-llms.md " lass AnswerWithIntermediateCalculations"
-> "class ..." (missing the c)
jinja-proposal.md "topic": "...7890" <- no comma
"banned_words": [...]
two adjacent string literals, so the dict
key after them is a syntax error
Once those parse, black can format them, so the rest of the change is what
pytest-examples' own formatter produces: joined lines that now fit, and blank
lines black adds or removes between definitions.
In jinja-proposal.md the formatter also restored `#> ` on an output comment that
had drifted to `# >`. `#> ` (with the trailing space) is pytest-examples'
`comment_prefix`; `# >` is not matched as an output marker.
Deliberately not touched: introducing-structured-outputs.md. Its block contains
a bare `#> ` marker standing for an empty printed line, and that form cannot
survive formatting -- black strips the trailing space, the result no longer
matches `comment_prefix`, and black then rewrites it to `# >`, which both breaks
the marker and leaves it inconsistent with the `#> ...` lines under it. Writing
`# >` into the docs to satisfy the linter seemed worse than leaving it, so it is
in the group below.
The remaining 18 need a call I did not want to make unilaterally, since they are
published posts:
- empty ```python blocks where install instructions appear to have been lost
(multimodal-gemini.md, generating-pdf-citations.md) -- the prose introduces
a snippet that is not there
- pseudo-code fenced as python, e.g.
`client.create(..., response_model=type[T]) -> T` in version-1.md, which is
a type signature rather than a statement
- fragments that were never standalone modules, e.g. a bare `@field_validator`
in chain-of-density.md
For those the options are to complete the snippet, re-fence as ```text (only
fences starting with `py`/`{.py` are collected), or exclude older posts from the
lint. Happy to follow up with whichever you prefer.
Collaborator
|
Consolidated into #2597 for Instructor 1.17.0: #2597 . The documentation change is included (overlapping typo edits are deduplicated), with contributor attribution retained where applicable. The combined documentation suite passes 610 checks with 89 existing skips. Closing this source PR as superseded; the consolidation PR remains draft pending full release validation and review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
tests/docs/test_posts.pylints every code block underdocs/blog/postswith black via pytest-examples. 34 of them fail onmain, which is whyweekly-testsand thereleasejob's test step are both red:This fixes 16 of the 34, taking it to
18 failed, 244 passed.Two were genuinely broken Python
A reader copying either of these gets a
SyntaxError:bad-schemas-could-break-llms.md— missing thec:jinja-proposal.md— missing comma, so the two strings concatenate and the following dict key is a syntax error:The rest is the formatter's own output
Once those two parse, black can format them. Everything else here is what pytest-examples' formatter produces — joined lines that now fit the width, and blank lines black adds or removes between definitions. I ran only the
formatstep, not--update-examples: the latter also callsrun_print_update, which executes the examples and fails without provider API keys (it takes the suite to 240 failures).In
jinja-proposal.mdthe formatter also restored#>on an output comment that had drifted to# >.#>— with the trailing space — is pytest-examples'comment_prefix;# >isn't matched as an output marker, so this is a repair.One file deliberately left alone
introducing-structured-outputs.mdis excluded. Its block has a bare#>marker standing for an empty printed line, and that form can't survive formatting: black strips the trailing space, the result no longer matchescomment_prefix, and black then rewrites it to# >— which breaks the marker and leaves it inconsistent with the#> ...lines directly beneath it:Writing
# >into the docs to satisfy the linter seemed worse than leaving the block failing, so it's in the group below.The remaining 18 need a decision I didn't want to make alone
These are published posts, and each needs a judgement about intent:
```pythonblocks where install instructions appear to have been lost —multimodal-gemini.mdandgenerating-pdf-citations.mdboth introduce a snippet with prose ("let's set up our environment with the necessary libraries:") and then show an empty blockclient.create(..., response_model=type[T]) -> Tinversion-1.md, a type signature rather than a statement@field_validatorinchain-of-density.mdThe options are to complete the snippet, re-fence as
```text(only fences starting withpy/{.pyare collected byfind_examples), or exclude older posts from the lint entirely. Happy to follow up with whichever you'd prefer — I didn't want to rewrite published posts on my own judgement.Verification
No source code touched — docs only.