📝 Fix `format_sse_event` docstring rendering of `\n\n` terminator by AshNicolus · Pull Request #15613 · fastapi/fastapi · GitHub
Skip to content

📝 Fix format_sse_event docstring rendering of \n\n terminator#15613

Open
AshNicolus wants to merge 4 commits into
fastapi:masterfrom
AshNicolus:fix/sse-format-docstring-escape
Open

📝 Fix format_sse_event docstring rendering of \n\n terminator#15613
AshNicolus wants to merge 4 commits into
fastapi:masterfrom
AshNicolus:fix/sse-format-docstring-escape

Conversation

@AshNicolus

Copy link
Copy Markdown
Contributor

Summary

The docstring for fastapi.sse.format_sse_event describes the SSE event terminator as \n\n inside backticks. Because the docstring is a regular Python string (not raw), \n is interpreted as a newline at parse time, so the rendered docstring — e.g. via help(format_sse_event) or any generated reference docs — shows two blank lines between empty backticks instead of the intended \n\n escape sequence.

Escaping the backslashes (\\n\\n in source) makes the rendered text match what was intended.

Before

The result always ends with (the event terminator).

After

The result always ends with \n\n (the event terminator).

Test plan

  • python -c "from fastapi.sse import format_sse_event; print(format_sse_event.__doc__)" shows the corrected rendering.
  • ruff check fastapi/sse.py passes.
  • ruff format fastapi/sse.py --check passes.
  • No code-path change — only the __doc__ string content changes; runtime behavior of format_sse_event is identical.

@codspeed-hq

codspeed-hq Bot commented May 26, 2026

Copy link
Copy Markdown

@YuriiMotov YuriiMotov changed the title Fix format_sse_event docstring rendering of \n\n terminator 📝 Fix format_sse_event docstring rendering of \n\n terminator May 26, 2026

@YuriiMotov YuriiMotov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Before:

Image

After:

Image

@YuriiMotov YuriiMotov added the docs Documentation about how to use FastAPI label May 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants