[ty] Fix docstring rendering for literal blocks after doctests#22676
Merged
MichaReiser merged 1 commit intomainfrom Jan 23, 2026
Merged
[ty] Fix docstring rendering for literal blocks after doctests#22676MichaReiser merged 1 commit intomainfrom
MichaReiser merged 1 commit intomainfrom
Conversation
888b63d to
4dee0e1
Compare
MichaReiser
commented
Jan 19, 2026
| block_indent = 0; | ||
| in_any_code = false; | ||
| in_literal = false; | ||
| in_doctest = false; |
Member
Author
There was a problem hiding this comment.
I'm not a 100% sure about this change but opening a doctest only sets in_any_code and in_doctest to true. Ending a doctest should, therefore, set in_doctest and in_any_code to false.
It also seems that in_literal and in_doctest are exclusive to each other. It could make sense to use an enum over Text, Doctest, Literal with an is_code() as state variable instead, to make this clear.
2c146e6 to
d270098
Compare
Typing conformance resultsNo changes detected ✅ |
This comment was marked as outdated.
This comment was marked as outdated.
Member
Author
|
Uff, thanks RustRover for making all the formatting changes. Love it |
d649ea5 to
6c2fc11
Compare
When a doctest ended on a blank line, `in_doctest` was not reset to `false`. This could cause issues when a docstring contained a doctest followed by a literal block (::) with blank lines inside it. In that scenario, a blank line inside the literal block would incorrectly trigger the doctest-ending logic (because `in_doctest` was still `true` from the earlier doctest), prematurely closing the literal block and causing subsequent code content to be rendered as regular text with ` ` indentation instead of being inside the code block. Fixes astral-sh/ty#2497
6c2fc11 to
863995f
Compare
Member
Author
|
I'll merge this. Seems easy enough to revert if it's wrong and there's a new test |
carljm
added a commit
that referenced
this pull request
Jan 30, 2026
* main: (62 commits) [`refurb`] Do not add `abc.ABC` if already present (`FURB180`) (#22234) [ty] Add a new `assert-type-unspellable-subtype` diagnostic (#22815) [ty] Avoid duplicate syntax errors for `await` outside functions (#22826) [ty] Fix unary operator false-positive for constrained TypeVars (#22783) [ty] Fix binary operator false-positive for constrained TypeVars (#22782) [ty] Fix false-positive `unsupported-operator` for "symmetric" TypeVars (#22756) [`pydocstyle`] Clarify which quote styles are allowed (`D300`) (#22825) [ty] Use distributed versions of AND and OR on constraint sets (#22614) [ty] Add support for dict literals and dict() calls as default values for parameters with TypedDict types (#22161) Document `-` stdin convention in CLI help text (#22817) [ty] Make `infer_subscript_expression_types` a method on `Type` (#22731) [ty] Simplify `OverloadLiteral::spans` and `OverloadLiteral::parameter_span` (#22823) [ty] Require both `*args` and `**kwargs` when calling a `ParamSpec` callable (#22820) [ty] Handle tagged errors in conformance (#22746) Add `--color` cli option to force colored output (#22806) Identify notebooks by LSP didOpen instead of `.ipynb` file extension (#22810) [ty] Fix docstring rendering for literal blocks after doctests (#22676) [ty] Update salsa to fix out-of-order query validation (#22498) [ty] Inline cycle initial and recovery functions (#22814) [ty] Pass the generic context through the decorator (#22544) ...
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.
Summary
When a doctest ended on a blank line,
in_doctestwas not reset tofalse. This could cause issues when a docstring contained a doctest followed by a literal block (::) with blank lines inside it.In that scenario, a blank line inside the literal block would incorrectly trigger the doctest-ending logic (because
in_doctestwas stilltruefrom the earlier doctest), prematurely closing the literal block and causing subsequent code content to be rendered as regular text with indentation instead of being inside the code block.Fixes astral-sh/ty#2497
Test Plan
Added test