Skip to content

Black crashes on files containing \r, from e.g. old MacOS #3700

@Zac-HD

Description

@Zac-HD

Black currently fails on files containing a carriage return in many positions, while Python itself is happy to treat \r as a newline.
For example:

import black
black.format_str("{\r}", mode=black.Mode())

This is obviously a trivial example, but the problem occurs for a fairly wide range of old Python code from e.g. MacOS, or when files are loaded without universal-newlines (which does still happen occasionally).

As a fix, I don't think it's worth trying to fix lib2to3, but 'on error check for \r, rewrite and retry' seems reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions