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

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

📝 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

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 Bot commented May 26, 2026
edited
Loading

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 20 untouched benchmarks

Comparing AshNicolus:fix/sse-format-docstring-escape (1180fea) with master (99a1b1e)1

Footnotes

  1. No successful run was found on master (91dba44) during the generation of this report, so 99a1b1e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality Hide comment

LGTM!

Before:

After:

YuriiMotov added the docs Documentation about how to use FastAPI label May 26, 2026
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

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Footer

© 2026 GitHub, Inc.