Skip to content

File-specific line-endings misbehaviour when doing in-place black #3347

@bwagner

Description

@bwagner

File-specific line-endings misbehaviour when doing in-place black

I'm using a mac to contribute to a project that has python files with windows formatting CRLF. When I apply black to these files, black seems to break the line-end-formatting of the files. There's a possibly related issue with a solution, but doesn't seem to work properly in my situation.

To Reproduce

$ mkdir simple
$ cd simple
$ git init
$ printf "#black will touch this comment\n# black won't touch this comment\n#black will touch this comment\n# black won't touch this comment\n" > simple.py
$ unix2dos simple.py
$ git add simple.py && git commit -m "initial add" simple.py
$ black simple.py
$ git diff simple.py
diff --git a/simple.py b/simple.py
index cf57a10..886c794 100644
--- a/simple.py
+++ b/simple.py
@@ -1,4 +1,4 @@
-#black will touch this comment
+# black will touch this comment^M
 # black won't touch this comment
-#black will touch this comment
+# black will touch this comment^M
 # black won't touch this comment

Expected behavior

Same output as above but without the "^M" at the ends.

Environment

  • Black's version: black, 22.10.0 (compiled: yes)
  • OS and Python version: macOS 12.6 (Monterey) / Python 3.10.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions