Skip to content

Conversation

@MichaReiser
Copy link
Member

Summary

Fixes #18667

The Printer only supports \n. We, therefore, need to normalize the newlines in debug texts during formatting.

Normalizing the newlines doesn't change the Python semantics because Python normalizes all newlines to \n

Test Plan

Added snapshot test

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Jun 14, 2025
@github-actions
Copy link
Contributor

ruff-ecosystem results

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

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

Nice! This makes sense to me.

@MichaReiser
Copy link
Member Author

I was a bit confused why this would lead to duplicate lines but I think I understand it now:

  1. We infer \r\n as the used line ending because it's the first we see
  2. The printer replaces every \n with \r\n which results in \r\r\n after the first formatting pass

Now we have two line breaks. The printer will now infer \r as the line ending, and replace the \n with \r, now we have three line endings. The editor might also decide to convert the \r to \r\n, in which case this goes on forever

@MichaReiser MichaReiser merged commit 8237d46 into main Jun 15, 2025
34 checks passed
@MichaReiser MichaReiser deleted the micha/debug-text-newline branch June 15, 2025 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter adds extra carriage return to multiline f-string debug replacements

3 participants