Repository navigation
Respect --skip-source-first-line when formatting stdin - #5580
Merged
Merged
Conversation
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.
Description
--skip-source-first-line(-x) is honoured when formatting files by path, but it is silently ignored when the code is passed through stdin (black -x -). Instead, the first line is formatted along with the rest. When that line isn't valid Python, which is the case the option exists for (e.g. a Windows batch wrapper), Black fails to parse it:The same file formatted by path works. With
--diff/--checkon stdin, an unformatted first line also shows up as a change and makes the check fail.format_file_in_place()splits the header off before decoding and prepends it again afterwards, butformat_stdin_to_stdout()never looked atmode.skip_source_first_line. It now does the same. This includes the existing CRLF handling for headers, so the output doesn't end up with\r\r\n. The header is kept for write-back and for--diff/--color-diffoutput.Checklist - did you ...
--previewstyle, following the stability policy? (no style change, CLI/IO fix only)CHANGES.mdif necessary? (under "Output")test_skip_source_first_line_via_stdin, LF and CRLF, write-back and--diff; fails without the fix)